If the binary_sensor hasn’t changed since the restart then I assume the device_tracker won’t be set after a restart.
it’s a long time since I setup our presence automations, but I included a set of automations that run on
trigger:
- platform: homeassistant
event: start
to determine the startup state of the custom presence descriptions we use.
When I added the device_tracker.see trackers I also added a call to the service for each device_tracker to set the initial state from the relevant binary sensor.
What I am trying to do is creating a second automation, that if homeassistant is restartet the automation is triggered. Just writing it down the independent from the syntax also the logic is not really working is it? So what is the suggest how to adjust this code:
alias: Presence Giga Red
description: ''
trigger:
- platform: state
entity_id: binary_sensor.gigaset_red
condition: []
action:
- service: device_tracker.see
data:
dev_id: gigagregor
location_name: |
{% if trigger.to_state.state == 'on' %}
home
{% elif trigger.to_state.state == 'off' %}
not_home
{% else %}
unknown
{% endif %}
source_type: router
mode: single
max: 10
Perhaps you should post some code, because the start event is a completely standard automation trigger listed in the docs and I’ve been using it for a number of years.
Homeassistant seems to convert it somehow automatically. And it does work for the other automation and I don’t think this is the problem. I assume the problem is, that the object is missing as the binary sensor is not at all part of this automation.
Ah ok.
I create my automations in YAML so my mistake - that’ll teach me not to try and provide a quick response whilst coding elsewhere. Apologies for the confusion.
You need to use the binary_sensor state (which will persist through restarts) to set the initial device_tracker state on startup.
You can use trigger.to_state.state with the other automation replicating changes from binary_sensor to device_tracker.
I got your point and I guess I am not able to explain myself probably, so I will try again.
In order to replace the device with the sensor data I need to read the sensor data.
Which for the automation that is constantly checking I do with example.
For my second automation the trigger is not the binary sensor but the homeassistant restart. Therefore no value. I tried to replace
trigger.to_state.state with state.binary_sensor.gigaset_red or binary_sensor.gigaset_red.state
Will take your advice of sharing code for next time.
Thanks for your help now everything works fine.
For documentation purpose I am putting everything here in one place.
alias: Presence Giga Red
description: ''
trigger:
- platform: state
entity_id: binary_sensor.gigaset_red
condition: []
action:
- service: device_tracker.see
data:
dev_id: gigagregor
location_name: |
{% if trigger.to_state.state == 'on' %}
home
{% elif trigger.to_state.state == 'off' %}
not_home
{% else %}
unknown
{% endif %}
source_type: router
mode: single
max: 10
This seems not to work anymore as the device_tracker configuration now expects a platform to be set and there is not platform for binary sensor, is there?