I have a fewe motion sensors that trigger some events. For example if i go into the kitchen after a certain time it turns the lights on and another that turns them off after a period of time. Changed my router reconnected every thing and now they do not trigger.
I can go into Automatons and click execute and they work. Anyone know what i am doing wrong.
- alias: Turn on kitchen light when there is movement
initial_state: true
trigger:
platform: state
entity_id: binary_sensor.motion_sensor_158d00020e5e79
to: 'on'
condition:
condition: and
conditions:
condition: time
after: '19:00:00'
before: '07:00:00'
action:
service: homeassistant.turn_on
entity_id: switch.other_thing
This caught me out a few times early on. It’s natural to think of night-time as “between 1900 and 0700”, but from the clock’s point of view, it’s 1900 to 2359 on one day, then resets to 0000 on the next day as a completely separate “section of time”.
Of course, you can code day-time as after 0700 and before 1900, and that would work just fine.
Actually, for a time condition, that works and it means just what you would think – between 7:00 PM in the evening and 7:00 AM the next morning. (It’s not the same as with the sun condition, which, BTW, should be changed to allow this, which I’ve looked into doing, but it’s a bit more complicated than it seems on the surface.) So, anyway, that’s not the problem.
Have you looked at the history of binary_sensor.motion_sensor_158d00020e5e79? Is it changing to 'on' from something else? Is the automation turned on? Have you tried calling the automation.trigger service from the SERVICES tab with skip_condition set to false during the specified time range?
Thanks for you help. It was me being stupid. The code worked but it was past 7 am when i checked it. so it did not trigger Sometimes you just need to check the obvious.
Would be very interested on how i could get this to work on the sun condition because as you alluded to It depends on the time of year it would need to trigger the automation.
The point is that the sun will disappear behind a building when it is BOTH below 12° elevation and its azimuth is above 272°.
So I wait for both of these to be true.
If the sun is below 12° above horizon, it will still shine in if it has not passed behind the building at 272°.
(This happens in the spring and autumn, when the sun is low in the sky).
But in the summer, the sun can be well past 272°, and still be above the 12° elevation of the building.
So when both conditions are true (and I don’t know which one will be true first, because that depends on the season), the awning will be moved to the “up” position.