Hello all, new user here, I have an access control system that allows scanning RFID cards to open/close an overhead door. My existing system uses a custom VB .NET application to do an SQL lookup, confirm the tag is authorized, then actuates the door and sends me a text if a flag is set in the DB. However, Verizon is now deeming all my text notifications to myself as spam and started blocking them. I’ve decided to go down the Home Assistant rabbit hole, but I’ve hit a snag. It looks like doing a DB lookup from HA is out of the cards, so I tried hard coding the tags in a script but I’m having some trouble wrapping my head around variables in scripts. Here is the script I’ve put together, but it doesn’t work.
alias: RFID Test
sequence:
- variables:
tag_name: unknown
grant_access: false
send_note: false
- choose:
- conditions:
- condition: state
state: "0123456789"
entity_id: sensor.test_rfid_reader
sequence:
- variables:
tag_name: Test Card Good
grant_access: true
- conditions:
- condition: state
state: "1234567890"
entity_id: sensor.test_rfid_reader
sequence:
- variables:
tag_name: Test Keychain Good
grant_access: true
send_note: true
- if:
- "{{ grant_access }}"
then:
- service: mqtt.publish
data:
topic: TEST/COMMAND
payload: ACTUATE
else:
- service: mqtt.publish
data:
topic: TEST/COMMAND
payload: DENY
alias: Unauthorized Tag
- service: notify.mobile_app_pixel_7
data:
message: Access DENIED to tag {{states('sensor.test_rfid_reader')}}
title: Alert
data:
ttl: 0
priority: high
- if:
- "{{ send_note }}"
then:
- service: notify.mobile_app_pixel_7
data:
message: Access GRANTED to tag {{ tag_name }}
title: Alert
data:
ttl: 0
priority: high
mode: single
Then I stumbled upon this statement in the docs “Variables have local scope. This means that if a variable is changed in a nested sequence block, that change will not be visible in an outer sequence block.” SO what’s the point of variables if you can’t modify them in a conditional? Will I have to create a choose option with the appropriate publish and notify services for each and every tag number? (there are dozens of them so I’m hoping not)
Thanks