rednblkx / HAP-ESPHome

Apple HomeKit for ESPHome
101 stars 11 forks source link

Read traditional NFC tags as well #20

Closed carlos-leopoly closed 2 weeks ago

carlos-leopoly commented 2 weeks ago

Could you expose to lambda the data of a traditional tags as well? Like Endpoint ID and Issuer ID. It would be nice to also read/authenticate with tradtional NFC cards.

I could use to some additional attributes like:

Thanks!

rednblkx commented 2 weeks ago

Hi!

Thanks for the suggestion, however, this is beyond scope given the context of ESPHome as this is already achievable through ESPHome’s own pn532 component and the same pn532 components present here are from the ESPHome repo just with some small changes to fit the homekey.

That being said, I don’t see a reason to integrate those things like that other than to just mangle them but I would be glad to be proved wrong.

Afaik the modified components should still work about the same but there could be bugs introduced by the patches, let me know if that is the case.

carlos-leopoly commented 2 weeks ago

Hi rednblkx, Thanks for paying attention to my request. I'm quite new to ESPHome so probably that's why I have not considered your suggestion to simply use the pn532 component in a standalone way. I would like to combine your project with the tagreader project of adonno. So probably I'll just copy the config entries from that project.

So you should be right, that's out of the scope of your project. Thank you anyway and thank you for your current project as well!

rednblkx commented 2 weeks ago

Alright, great! Let me know if you have any issues.

ss83 commented 5 days ago

Hi, first of all thank you for your work! This project is great, especially the way I can now use Homekey for my automations.

I had the same idea and wanted to use the ESPHome pn532 binary_sensor for normal NFC Tags.

The ESPHome code looks like:

binary_sensor:
  - platform: pn532
    uid: 12-34-56-78
    name: "PN532 NFC Tag"

When compiling it fails with the error:

binary_sensor.pn532: [source /config/homekey.yaml:82]

  Platform not found: 'binary_sensor.pn532'.

In a separate device without the HAP-ESPHome component it works fine. I am not a programmer, so this is the only input I can provide for now.

Best regards

carlos-leopoly commented 4 days ago

Hi @ss83,

This approach does work for me:

spi:
  clk_pin: 18
  miso_pin: 19
  mosi_pin: 23

pn532_spi:
  id: pn532_board
  cs_pin: 5
  update_interval: 100ms
  on_tag:
  - if:
      condition:
        lambda: 'return ( id(source)=="uid" );'
      then:
         - homeassistant.tag_scanned: !lambda |-
            ESP_LOGD("tagreader", "No HA NDEF, using UID");
             return x;
     else:
            - if:
                condition:
                  lambda: 'return ( id(source)=="hass" );'
                then:
                - homeassistant.tag_scanned: !lambda 'return id(info);'
                else:
                - homeassistant.event:
                    event: esphome.music_tag
                    data:
                      reader: !lambda |-
                        return App.get_name().c_str();
                      source: !lambda |-
                        return id(source);
                      url: !lambda |-
                        return id(url);
                      info: !lambda |-
                        return id(info);

all got from project tagreader project of adonno.