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.’
Hi - would you mind sharing your template for the “sensor.plate_recognition_result” please? I’d like to adopt this way of managing the plates (via a todo list) but currently use the plate recognizer “watched plates” example template (and am struggling to write one like yours)
Like most people, my automations change over time as my experience grows. The automation has changed from using helpers to using variables within the automation. There are quite a few changes to the original automation which I have included below. The automation also checks if my wife gets system messages on her phone and at the end the automation sends the message to my Sonoff NSP panel in the hall next to the gate opener.
alias: Test platerecognizer response for known car
description: If the numberplate is recognised get the corresponding description
triggers:
- trigger: event
event_type: platerecognizer.vehicle_detected
conditions:
- condition: template
alias: More than 45 seconds since the previous check?
value_template: >
{{(as_timestamp(now()) -
as_timestamp(state_attr("automation.test_gate_mainstream_for_not_null_and_test_todo_for_known_car",
"last_triggered") | default(0)) | int > 45 )}}
actions:
- variables:
registration_plate: "{{ trigger.event.data.plate }}"
- data: {}
response_variable: myplates
action: todo.get_items
target:
entity_id: todo.plates
enabled: true
- alias: Message depending on plate recognition state
if:
- condition: template
value_template: |-
{{ myplates['todo.plates']['items']
| selectattr('summary','search', registration_plate )
| list
| count > 0 }}
alias: Plate is recognised
then:
- variables:
visitor_x: |-
{{ myplates['todo.plates']['items']
| selectattr('summary','search', registration_plate )
| map(attribute='description')
| list
| replace( "['","")
| replace ("']","") }}
- alias: Check if the gate is closed
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
enabled: true
alias: Open the Gate
- if:
- condition: state
entity_id: input_boolean.notify_her
state: "on"
then:
- action: notify.mobile_app_kirsty_mobile
data:
title: Gate
message: TTS
data:
tts_text: "\"{{ visitor_x}}\" at the gate. The gate is opening."
media_stream: alarm_stream
enabled: true
alias: >-
Notify Kirsty someone we know is at the gate and the gate is
opening
- if:
- condition: state
entity_id: input_boolean.notify_him
state: "on"
then:
- action: notify.mobile_app_alan_mobile
data:
title: Gate
message: TTS
data:
tts_text: "\"{{ visitor_x}}\" at the gate. The gate is opening."
media_stream: alarm_stream
alias: Notify Alan someone we know is at the gate and the gate is opening
- alias: Notify Hall someone we know is at the gate and it is opening
if:
- condition: template
value_template: " {% if states.zone.home.state | int > 0 %} true {% else %} false {%endif%}"
alias: Send Hall the message if someone is home
then:
- action: notify.mobile_app_hall_nsp
data:
message: TTS
data:
tts_text: >-
This is the gatekeeper, "{{ visitor_x}}" at the gate. The
gate is opening.
- action: switch.turn_off
metadata: {}
data: {}
target:
entity_id: switch.open_the_gate
enabled: false
alias: Turn off Open the Gate
else:
- if:
- condition: state
entity_id: input_boolean.notify_her
state: "on"
then:
- action: notify.mobile_app_kirsty_mobile
data:
title: Gate
message: TTS
data:
tts_text: >-
"{{visitor_x}}" at the gate. No need to do anything, the
gate is already open.
media_stream: alarm_stream
enabled: true
alias: Notify Kirsty someone has arrived
- if:
- condition: state
entity_id: input_boolean.notify_him
state: "on"
then:
- action: notify.mobile_app_alan_mobile
data:
title: Gate
message: TTS
data:
tts_text: >-
"{{visitor_x}}" at the gate. No need to do anything, the
gate is already open.
media_stream: alarm_stream
alias: Notify Alan someone has arrived
- alias: Notify Hall someone has arrived
if:
- condition: template
value_template: " {% if states.zone.home.state | int > 0 %} true {% else %} false {%endif%}"
alias: Send Hall the message if someone is home
then:
- action: notify.mobile_app_hall_nsp
data:
message: TTS
data:
tts_text: >-
This is the gatekeeper. "{{ visitor_x }}" at the gate. No
need to do anything, the gate is already open.
else:
- alias: Unknown vehicle at the gate - Alan
if:
- condition: state
entity_id: input_boolean.notify_him
state: "on"
then:
- 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 with
registration {{ registration_plate}}. I have started the gate
camera feed on your phone, for you to have a look?
media_stream: alarm_stream
alias: Notify Alan of unknown vehicle
- 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/alan_mobile
alias: Open Home assistant on phone
- if:
- condition: state
entity_id: input_boolean.notify_her
state: "on"
then:
- alias: Notify Kirsty of unknown vehicle
action: notify.mobile_app_kirsty_mobile
metadata: {}
data:
message: TTS
title: Gate
data:
tts_text: >-
Kirsty, There is a car at the gate that I don't recognise with
registration "{{registration_plate }}". I have started the
gate camera feed on your phone, for you to have a look?
media_stream: alarm_stream
- action: notify.mobile_app_kirsty_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
alias: Open Home assistant on phone
alias: Unknown vehicle at the gate - Kirsty
- alias: Unknown vehicle at the gate - Hall
if:
- condition: template
value_template: >-
{% if states.zone.home.state | int > 0 %} true {% else %} false
{%endif%}
alias: Send Hall the message if someone is home
then:
- action: notify.mobile_app_hall_nsp
data:
message: TTS
data:
tts_text: >-
This is the Gatekeeper, There is a car at the gate that I do
not recognise. Do you want to check please.
enabled: true
mode: single