Suppose we have an automation that turns on a bulb at 3pm and off at 5pm, every day.
Suppose that the bulb (a simple wifi bulb) goes offline at 2.59pm and goes online at 3.02 for whatever reason (connectivity etc…). The automation will not turn on the bulb because it was offline.
Is there a simple way that double check the condition of the bulb, and when it comes online again, it turns on/off the bulb anyway (even if it is out of trgger time), according the automation?
…I mean without writing other automations based on time trigger (e.g. every minute) that check the status of the bulb.
Add a State Trigger that monitors the bulb’s state when it changes fromunavailable (to any other state). If this state-change occurs between 3 and 5 PM (using a condition), the automation can turn on the bulb.
What I do expect is that the bulb be ON between 15:00 and 17:00, and OFF in the remaining time.
If the bulb is always online, NO PROBLEM. It will be turned ON (or OFF) by automation.
But, if the bulb goes offline at 14.59 and become online again at 15:02, the bulb will be remain OFF.
I want the bulb be turned ON at 15.00. If it is offline at 15.00, I want it be turned ON as soon as it becomes online at 15.00 < t < 17.00, according the automation
If the the bulb loses its Wi-Fi connection, Home Assistant reports its state as being unavailable. If the bulb’s state is unavailable at 15:00 the automation’s command to turn it on will fail to work. However, let’s say the bulb reconnects to Wi-Fi at 15:06. Its state will change from unavailable to (probably) off. That state-change will be detected by the State Trigger and the action will turn on the light bulb.
The condition is needed to ensure the bulb is controlled exclusively during the desired time range.
That’s yet another way to do it but not necessarily a simpler way.
In the first example, each trigger specifies which action (turn the light on or off) should occur (using the trigger’s id). The service call doesn’t perform any decision and simply performs the specified action.
In the second example, each trigger does not specify which action should occur. Therefore the automation’s action requires a choose to determine if it should turn the light on or off.
They both do the same thing but the second one requires slightly more code to achieve the desired result.