Thanks, your german is fine. I changed my mind for that automation.
My goal now looks a little different.
The reed sensor is attached to a post box.
Usually one time a day the post man open and close it, this will turn on and off my binary sensor.
Besides being notified about that (already have this)
I want to be able to ask alexa about the postbox.
Pseudocode:
If binary sensor was on today (since 00:00)
Postman was here at {{ sensordate time, should output E.g. 9:33}}
If binary sensor was not on today
Post man wasn’t here today
Thanks, I think that would work. Unfortunately I did tell that there are two guys that open the postbox. The first one usually at around 6AM is not interesting, as he only delivers ad’s.
So I think I need the condition to only get true after lets say 8 AM (postman comes from arround 9 to open end).
Additionally I have another issue: {{as_timestamp(now()) | timestamp_custom("%H:%M", false)}}
gives me the wrong time.
it gives me 12:30 and should be 13:30 (UTC+2).
I run hassio and my time sensor shows the right time. But the template above doesn’t.
Ok, setting it to true and it shows the right time now.
However I’m confused about the timezone setting now.
The sensor.time sensor of home assistant feeded with my location data shows the right time but tells me UTC+2.
But actually the right timezone (wintertime) would be UTC+1 currently, what explains the one hour difference in the example above when switching true/false.
So all times are right, but it seems like the sensor name UTC+2 is wrong.
Maybe because I set up this sensor when we had summertime? And afterwards the sensornamed stayed?
I think I have to add int for the minutes too, because 09:08, will get 9:08 right? I think I got everything to make it work now. Will post a working script when its ready.
Nevertheless other questions could appear
routine_postkasten:
sequence:
- service: media_player.alexa_tts
data_template:
entity_id: '{{ states.sensor.last_alexa.state }}'
message: >
{% if as_timestamp(states.binary_sensor.zigbee_postkasten_contact.last_changed) | default(0) | timestamp_custom("%H", true) | int >= 8 %}
Post war heute um {{as_timestamp(states.binary_sensor.zigbee_postkasten_contact.last_changed) | timestamp_custom("%H", true) | int }} Uhr {{as_timestamp(states.binary_sensor.zigbee_postkasten_contact.last_changed) | timestamp_custom("%M", true) | int }} da
{% else %}
Post war heute noch nicht da
{% endif %}
With this I’m able to ask Alexa if the postman was already here.
I have the same issue. When restarting HA all last_changed and last_updated attributes are reset.
Only way round would be to have an automation that updates a template sensor that tracks that data, you could try something like (not tested):