So, I made a simple alarm. I used examples from the help. And also fragments from this forum.
The system receives the tag value and if it is correct then the security is disabled.
The task is to be able to change the tag to a new one if necessary. And disable the old one in case of its loss or theft.
How to do this without reflashing?
Here is a basic example of code-
# Example configuration entry
spi:
clk_pin: GPIO1
miso_pin: GPIO0
mosi_pin: GPIO4
pn532_spi:
cs_pin: GPIO5
on_tag:
then:
- homeassistant.tag_scanned: !lambda 'return x;'
- if:
condition:
or:
- binary_sensor.is_on: tag1
- binary_sensor.is_on: tag2
then: #this is where you would code your actions
- logger.log: "Valid NFC tag detected"
- rtttl.play: 'long:d=1,o=4,b=60:e4'
- switch.turn_on: door
else:
- logger.log: "Invalid NFC tag detected"
- rtttl.play: 'long:d=4,o=5,b=200:a,32p,a,32p,a'
switch:
- platform: gpio
pin: GPIO7
name: "door"
id: door
icon: "mdi:gate"
on_turn_on:
- delay: 5s
- switch.turn_off: door
# PIEZO buzzer
output:
- platform: ledc
pin: GPIO10
id: rtttl_out
rtttl:
output: rtttl_out
binary_sensor:
- platform: pn532
uid: 7A-4F-27-15
id: tag1
- platform: pn532
uid: 7B-36-DE-19
id: tag2
Here in the binary sensor block specific IDs are specified.
I need to be able to change or add a label from HA.
I tried to use the number component, the text sensor, and finally the lambda call. But without success.
When trying to use lambda in the binary sensor component, the PN532 platform writes that this component does not support lambda calls.
Is it really impossible to solve such an important task using esphome?
Thank you for your recommendations. The thing is that this is a simple block of the security system. And here autonomy is important to increase reliability. HA provides additional functionality, but it should not be a mandatory component. There may be an update, configuration adjustment, reboot, etc. at an inopportune moment.
Therefore, let’s move on to point 2.
Yes, it is possible to use a text sensor.
But how to use the received value in the UID field?
Lambda does not work there, the compiler reports that the sensor platform does not support lambda.
Here’s what the automation fragment looks like.
You can set actions when the sensor is triggered, but I haven’t found a single way to replace the sensor itself without reflashing.
the thing is, this UID tag can be easily copied so this is not a secure setup. If you want to make it secure, put dumb passive tag on the wall so anybody can scan it to get the UID. And only your phone after scanning this particular UID will run HAss action to open the door. This can be done with Shortcuts on iOS and probably some other way on Android.
But if you insist, set the text template sensor in esphome. Fill it in HA. Move the automation to on_tag lambda. Use condition to check if scanned tag equals UID set in HA.
That would be something like
- if:
condition:
lambda: 'return id(text_sensor_id).state == x ;'
then: #this is where you would code your actions
- logger.log: "Valid NFC tag detected"
- rtttl.play: 'long:d=1,o=4,b=60:e4'
- switch.turn_on: door
else:
- logger.log: "Invalid NFC tag detected"
- rtttl.play: 'long:d=4,o=5,b=200:a,32p,a,32p,a'