I know it looks simple but I couldn’t do it. I need an automation to turn a switch on when it becomes available/connected to HA.
Example: When I connect a Sonoff to the power, it will connect to my home assistant, the device status will change to ‘available’. Then my HA automation will detect that the device status has changed from ‘unavailable’ to ‘available’. Then it will turn on the the switch.
I know I could use the Power on State configurarion but I don’t want to do that. I need it to be done via automation.
Can anyone help me here?
- id: '1604858642794'
alias: Pump 1
description: ''
trigger:
- platform: state
entity_id: switch.pump_1
from: unavailable
to: available
condition: []
action:
- service: switch.turn_on
data: {}
entity_id: switch.pump_1
mode: single
I was investigating a little bit further and there is something strange here. Even if I cut the Sonoff’s power HA (device history) still shows the status as ‘off’ and not as ‘unavailable’. How can I solve that?
With the MQTT sensors on my system, they only get state “unavailable” when HA restarts in the period where they don’t get updated. Otherwise they retain their last state. You may be seeing the same here.