From a1d9bc76aabfe1aecaf1db9dabaa98b0e23e3ac5 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 17 Sep 2020 07:17:53 +0000 Subject: [PATCH 1/2] Drop usage of custom component --- README.md | 9 ++--- custom_components/esphome_tag.py | 62 -------------------------------- tagreader.yaml | 37 ++++++++++--------- 3 files changed, 23 insertions(+), 85 deletions(-) delete mode 100644 custom_components/esphome_tag.py 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 2865661..8937475 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 @@ -55,7 +55,7 @@ globals: - id: led_enable type: bool initial_value: 'true' - + switch: - platform: template name: "Sound" @@ -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 @@ -113,7 +113,7 @@ api: level: 50% - delay: 120ms - output.turn_off: buzzer - + - service: rfidreader_tag_ko then: - output.esp8266_pwm.set_frequency: @@ -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 @@ -141,14 +141,13 @@ pn532: - text_sensor.template.publish: id: rfid_tag state: !lambda 'return x;' + # Once ESPHome 1.15.2 or later is released, upgrade this according to + # https://github.com/adonno/tagreader/issues/6 - homeassistant.event: - event: esphome.rfid_read - data: - device_id: $devicename - data_template: - tag_id: !lambda 'return x;' - - - if: + event: esphome.tag_scanned + data: + tag_id: !lambda 'return x;' + - if: condition: lambda: "return id(led_enable);" then: @@ -161,7 +160,7 @@ pn532: - delay: 500ms - light.turn_off: id: activity_led - - if: + - if: condition: lambda: "return id(beep_sound_state);" then: @@ -191,12 +190,12 @@ pn532: - + output: - platform: esp8266_pwm pin: D8 id: buzzer - + text_sensor: - platform: template @@ -204,7 +203,7 @@ text_sensor: id: rfid_tag - platform: template - id: connected + id: connected @@ -218,4 +217,4 @@ light: id: activity_led restore_mode: ALWAYS_OFF name: "Activity LED" - internal: true \ No newline at end of file + internal: true From cfb460170a2cf584c3f8635596a5d994a7053bb8 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 17 Sep 2020 10:10:39 +0200 Subject: [PATCH 2/2] Update tagreader.yaml Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> --- tagreader.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tagreader.yaml b/tagreader.yaml index 8937475..1bfeb8d 100644 --- a/tagreader.yaml +++ b/tagreader.yaml @@ -144,9 +144,9 @@ pn532: # Once ESPHome 1.15.2 or later is released, upgrade this according to # https://github.com/adonno/tagreader/issues/6 - homeassistant.event: - event: esphome.tag_scanned - data: - tag_id: !lambda 'return x;' + event: esphome.tag_scanned + data: + tag_id: !lambda 'return x;' - if: condition: lambda: "return id(led_enable);"