Tag_scanned event - anything change recently?

Here’s the critical part of an ESPHome rfid tag reader device that was working well triggering an automation for many weeks, then recently stopped functioning.

sensor:
  platform: custom
  lambda: |-
      auto wiegand = new WiegandReader(D6, D7);
      App.register_component(wiegand);
      return {wiegand};

  sensors:
    name: "Card ID"
    on_value: 
    - then:
      - homeassistant.tag_scanned: !lambda 'return uint32_to_string(x);'

Checked my automation using the tag, and all templated conditions were being properly evaluated.
Checked ESPHome device logs, and it shows the tag being read successfully.
Checked Developer Tools listening for the tag_scanned event and received zero results. :frowning:

Has something recently changed? The event name? The data/value format? Anything?
Reviewing the Home Assistant source at https://github.com/home-assistant/core/tree/dev/homeassistant/components/tag doesn’t show any changes in the last few months.

Try

on_value:
  then:

instead of

on_value:
  - then:

Thanks for that suggestion, I just tried it, and the following compilation error appeared:

/config/esphome/rfid-reader.yaml: In lambda function:
/config/esphome/rfid-reader.yaml:35:32: error: 'uint32_to_string' was not declared in this scope
       - homeassistant.tag_scanned: !lambda 'return uint32_to_string(x);'

which seriously has me scratching my head, now. :confounded:

That’s strange… you could try if this has the same result: return String(x);

Nope, that just gets into a different can of worms:

/config/esphome/rfid-reader.yaml: In lambda function:
/config/esphome/rfid-reader.yaml:35:22: error: could not convert 'String(x, 2)' from 'String' to 'std::string {aka std::basic_string<char>}'
       - homeassistant.tag_scanned: !lambda 'return String(x);'

Just found this

FYI, the following ESPHome lambda code works well.
Unfortunately, the tag_scanned event is still not registering in Home Assistant. :frowning:

sensor:
  platform: custom
  lambda: |-
      auto wiegand = new WiegandReader(D6, D7);
      App.register_component(wiegand);
      return {wiegand};

  sensors:
    name: "Card ID"
    on_value: 
      then:
      - homeassistant.tag_scanned: !lambda 'return to_string(x);'

Try to add this under then: to see if it triggers the then:

- logger.log: "Triggered"

If that does not display in the logs after scanning it is probably in the custom component.

1 Like

Yup, that appeared in the logs, as does my sensor value being updated:

[15:28:01][C][mdns:084]: mDNS:
[15:28:01][C][mdns:085]:   Hostname: rfid-reader
[15:28:44][D][Wiegand:053]: resultCode  = true
[15:28:44][D][Wiegand:054]: Tag scanned = 105133xx
[15:28:44][D][sensor:125]: 'Card ID': Sending state 105133xx.00000  with 0 decimals of accuracy
[15:28:44][D][main:039]: Triggered

And are you sure the ESP is still connected to Home Assistant in the Integrations tab?

1 Like

Well, you’ve finally hit the nail squarely :100: on the head. Thank you for your persistance with me this afternoon. The device is present in ESPHome, it returns logs in ESPHome, and it even shows up in the ESPHome integrations list. But when I list the entities associated with the device, up pops the big red exclamation point beside Card ID. No idea why this may have happened, haven’t changed anything in the device since I first got it working many weeks ago.

I’m going to drop the device from the ESPHome integration, and restart Home Assistant.
That should restore the entities properly.

2 Likes

You’re welcome, have a nice evening!

1 Like