I am using plate recognizer to get the registration of vehicles that arrive at the gate to my house. The purpose of my automation is to open the gate and notify me of the name of the driver that has arrived, not the registration plate.
To do this and be able to change the plate and name of the driver in the front end, I am using a todo list “plates” to hold the registration in the item.summary and the name of the person in the item.description
While I know that you can put a list of registrations in the app, this means I have to rebuild the code for every new friend/vehicle rather than making an addition to the todo list in the front end. It would be much cleaner to just update a list in the front end and the automation use the list to match.
I can get my automation to recognise the plate number in the todo list but I am struggling to get the corresponding item description (name of the driver) to use in my notification.
I get an empty string returned. I don’t get the desired item.description with the name of the driver.
The result returned is: ‘I am opening the gate, arrived.’
Any help would be greatly appreciated.
alias: AA Test for a number plate in todo.plates
description: "If the numberplate is recognised get the corresponding description (holding the name of the driver) and notify me.
triggers:
- trigger: state
entity_id:
- sensor.plate_recognition_result # holds the licence plate number from platerecognizer
conditions: []
actions:
- data: {}
response_variable: myplates
action: todo.get_items
target:
entity_id: todo.plates
- if:
- condition: template
value_template: >-
{{ myplates['todo.plates']['items']
| selectattr('summary','search',states.sensor.plate_recognition_result.state )
| list
| count > 0 }}
then:
- action: notify.mobile_app_alan_mobile
data:
message: >-
I am opening the gate,
{{myplates['todo.plates']['items']
| selectattr('summary','search',states.sensor.plate_recognition_result.state )
| map(attribute='description')
| list }} arrived.
else:
- action: notify.mobile_app_alan_mobile
metadata: {}
data:
message: >-
There is an unrecognised car at the gate. Do you want me to open
the gate and turn on the lights.
title: Gate
I suggest using trigger.to_state.state instead of states.sensor.plate_recognition_result.state in your selection filters. The latter will query the current state value of the sensor, which could have changed between the trigger event and when the templates are rendered.
Thanks for the tip. I will implement that. I should have mentioned in my first post that I get an empty string returned. I don’t get the desired item.description with the name of the driver.
The result returned is: ‘I am opening the gate, arrived.’
The solution to opening my gate when a known registration is detected from a todo list is complete. It now opens the gate for a recognised registration and alerts me with a tts message in the companion app that someone has arrived. If the gate is closed it opens it, otherwise it just informs me of the arrival. If it does not recognise the registration plate it sends a tts message to the companion app to notify me and opens home assistant on my phone at the camera stream so that I can take the appropriate action.
alias: Test for a number plate in todo.plates
description: If the numberplate is recognised get the corresponding description (
triggers:
- trigger: state
entity_id:
- sensor.plate_recognition_result
conditions: []
actions:
- data: {}
response_variable: myplates
action: todo.get_items
target:
entity_id: todo.plates
- if:
- condition: template
value_template: |-
{{ myplates['todo.plates']['items']
| selectattr('summary','search',trigger.to_state.state )
| list
| count > 0 }}
then:
- if:
- condition: state
entity_id: binary_sensor.gate_sensor_door
state: "off"
then:
- action: switch.turn_on
metadata: {}
data: {}
target:
entity_id: switch.open_the_gate
- action: notify.mobile_app_alan_mobile
data:
title: Gate
message: TTS
data:
tts_text: |-
{{ myplates['todo.plates']['items']
| selectattr('summary','search',trigger.to_state.state )
| map(attribute='description')
| list
| replace( "['","")
| replace ("']","")
}} at the gate. The gate is opening.
media_stream: alarm_stream
else:
- action: notify.mobile_app_alan_mobile
data:
title: Gate
message: TTS
data:
tts_text: |-
{{ myplates['todo.plates']['items']
| selectattr('summary','search',trigger.to_state.state )
| map(attribute='description')
| list
| replace( "['","")
| replace ("']","")
}} at the gate. No need to do anything, the gate is already open.
media_stream: alarm_stream
else:
- action: notify.mobile_app_alan_mobile
metadata: {}
data:
message: TTS
title: Gate
data:
tts_text: >-
"Alan, There is a car at the gate that I don't recognise. I have started the gate camera feed on your phone, for you to have a look?"
media_stream: alarm_stream
- action: notify.mobile_app_alan_mobile
metadata: {}
data:
message: command_activity
data:
intent_package_name: "io.homeassistant.companion.android"
intent_action: "android.intent.action.VIEW"
intent_uri: "homeassistant://navigate/lovelace/overview"