diff --git a/README.md b/README.md index 72bcd8c..26d5eb2 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ To build your own tag reader, you need the following components: The 3D models for the case are [here](https://github.com/adonno/tagreader/tree/master/STLs). ### Connecting the components + ![Photo of schematics](https://github.com/adonno/tagreader/blob/master/Schematics/tag_reader_schematics_v1.png) There are not too many components to connect, but it does require soldering. You will need the following: @@ -32,15 +33,15 @@ To flash the reader firmware to your D1 Mini you point ESPHome at [tagreader.yam ## Configuring for use with Home Assistant -If the tag reader is unable to connect to a wifi network, it will start a WiFi access point with a captive portal to allow you to enter your WiFi credentials. +The tag reader requires [Home Assistant](https://www.home-assistant.io) 0.115 or later. -The tag reader will be automatically found by Home Assistant once the tag reader is connected to the same network. You can follow the instructions in the UI to set it up. +If the tag reader is unable to connect to a wifi network, it will start a WiFi access point with a captive portal to allow you to enter your WiFi credentials. -A custom component is required for Home Assistant at this time to link the tag reader to the tag integration in Home Assistant. Copy [this file](https://raw.githubusercontent.com/adonno/tagreader/master/custom_components/esphome_tag.py) to `/custom_components/esphome_tag.py` and add `esphome_tag:` to your `configuration.yaml` file. +The tag reader will be automatically discovered by Home Assistant once the tag reader is connected to the same network. You can follow the instructions in the UI to set it up. ## Usage -Each tag that is scanned will result in a `tag_scanned` event in Home Assistant. You can manage your tags and automate them in the Home Assistant UI under config -> tags. +Scanned tags can be managed from the tags interface in Home Assistant. You can find it under config -> tags. ![Screenshot of the Home Assistant tag UI](https://raw.githubusercontent.com/adonno/tagreader/master/docs/tag-ui.gif) diff --git a/custom_components/esphome_tag.py b/custom_components/esphome_tag.py deleted file mode 100644 index 457c35d..0000000 --- a/custom_components/esphome_tag.py +++ /dev/null @@ -1,62 +0,0 @@ -from homeassistant.const import MAJOR_VERSION, MINOR_VERSION -from homeassistant.helpers import device_registry - -DOMAIN = "esphome_tag" - - -async def async_setup(hass, config): - if MAJOR_VERSION > 0 or MINOR_VERSION >= 115: - - async def scan_tag(tag_id, device_id): - await hass.components.tag.async_scan_tag(tag_id, device_id) - - else: - # Mimick tag integration in HA 0.115+ - async def scan_tag(tag_id, device_id): - hass.bus.async_fire( - "tag_scanned", - { - "tag_id": tag_id, - "device_id": device_id, - }, - ) - - device_ids = {} - - async def handle_event(ev): - # Find ESPHome Device ID - esphome_id = ev.data["device_id"] - - device_id = device_ids.get(esphome_id) - - if device_id is not None: - await scan_tag(ev.data["tag_id"], device_id) - return - - esphome_entry = None - - # Find ESPHome entry based on esphome_id - for entry in hass.config_entries.async_entries("esphome"): - if entry.unique_id: - esphome_entry = entry - break - - if esphome_entry is None: - await scan_tag(ev.data["tag_id"], device_id) - return - - # Find ESPHome device in registry - dev_reg = await device_registry.async_get_registry(hass) - devices = device_registry.async_entries_for_config_entry( - dev_reg, esphome_entry.entry_id - ) - - if devices: - device_id = devices[0].id - device_ids[esphome_id] = device_id - - await scan_tag(ev.data["tag_id"], device_id) - - hass.bus.async_listen("esphome.rfid_read", handle_event) - - return True \ No newline at end of file diff --git a/tagreader.yaml b/tagreader.yaml index 5b7c144..05b4b7d 100644 --- a/tagreader.yaml +++ b/tagreader.yaml @@ -41,10 +41,10 @@ esphome: id: buzzer level: 50% - delay: 100ms - - output.turn_off: buzzer + - output.turn_off: buzzer - globals.set: id: connecting - value: 'false' + value: 'false' globals: - id: beep_sound_state type: bool @@ -90,8 +90,8 @@ switch: - globals.set: id: led_enable value: 'false' - -#wifi insert your SSID and Your PWD once connected + +#wifi insert your SSID and Your PWD once connected wifi: ap: ssid: rfidreader @@ -123,7 +123,7 @@ api: id: buzzer level: 50% - delay: 250ms - - output.turn_off: buzzer + - output.turn_off: buzzer ota: password: !secret ESP_OTA_PWD @@ -139,13 +139,10 @@ pn532: #TODO #3 - Add condition to read only once every 5 seconds then: - homeassistant.event: - event: esphome.rfid_read + event: esphome.tag_scanned data: - device_id: $devicename - data_template: tag_id: !lambda 'return x;' - - - if: + - if: condition: lambda: "return id(led_enable);" then: @@ -158,7 +155,7 @@ pn532: - delay: 500ms - light.turn_off: id: activity_led - - if: + - if: condition: lambda: "return id(beep_sound_state);" then: @@ -186,9 +183,6 @@ pn532: - output.turn_off: buzzer - - - output: - platform: esp8266_pwm pin: D8 @@ -198,7 +192,7 @@ output: text_sensor: - platform: template - id: connected + id: connected light: