Hi
This isn’t a problem, I’m just posting a fix to an issue I’ve experienced during a power outage & it might be of help to others..
My Home Assistant system is on UPS, so stays active when LocalBytes plugs could lose and regain power when mains power fails. This issue isn’t a fault with the plugs, just an effect that occurs when mains power fails. When a power outage occurs, and mains power returns, the plugs will change from an unavailable or unknown state in HA to the appropriate value. I use LocalBytes plugs in 2 ways.
I use the plugs to trigger an action when the plug is turned on or off. Managing a power outages here is easy, as I only trigger a HA action when I see a plug transition from ON to OFF or OFF to ON. When a plug boots it will transition from unavailable or unknown status to off, so HA doesn’t trigger anything, which is good.
I also used the plugs to trigger an automation if the plug reports it goes above or below a certain power usage. This causes an issue as a newly powered on plug will report transition from unavailable or unknown status to 0 power usage, triggering an automation. There is no, built in, method in HA to comprehend a transition from one power number to another, if the plug reports 0W the automation will trigger.
To avoid the second issue I add a condition to the HA automation that does not trigger the automation if the previous condition was either unavailable or unknown. This can be done directly by editing the automations.yaml file and adding the code below to each automation:
condition:
- condition: template
value_template: '{{ trigger.from_state.state != "unavailable" }}'
- condition: template
value_template: '{{ trigger.from_state.state != "unknown" }}'
The same code can also be added to an automation in the HA visual editor by adding a couple of “And If” clauses entering value templates with the trigger lines above.