Setting a state to a switch based on the last state saved before restart

Hey guys

I’ve been looking around the community the web site to find how i could do this to no avail.
the only thing i found close to it was appdeamon although with my limited programming skills it’s a no go for me.

I think what i’m trying to get is fairly simple for the guys around here, so i’ll ask :slight_smile:

I have some RF switch that are working great except when HA is restarted. The state of those switches are returned to off even if the switches are “on” before restarting.

Knowing the the last state is saved in the DB i was wondering if there was a way to fetch the last state at start up and overwriting the new state with the value fetched from the DB ( API call or other )

here’s one of them as an example , as said earlier, it’s a really basic RF Switch

  Camera reset:
    protocol: 1
    pulselength: 185
    code_on: 5265155
    code_off: 5265164

thanks in advance guys

Anyways this is doable ?

It’s pretty annoying that everytime HA restarts those switches are returned to an “OFF” state

Any help is welcome

thanks

Hi,

I ran into the same problem with pilight and HA. Status is not recoverd after restart HA.
I have no solution.
Maybe we can do a feature request.

It would be a good thing that the persistent state gets added for all devices to manage them manually if needed

As in the mysensor component as for me this is more à bug than a feature request

Especially that it’s a component state and not an automation state

Ie

> # Example configuration.yaml entry
> mysensors:
>   gateways:
>     - device: '/dev/ttyUSB0'
>       persistence_file: 'path/mysensors.json'
>       baud_rate: 38400
>     - device: '/dev/ttyACM0'
>       persistence_file: 'path/mysensors2.json'
>       baud_rate: 115200
>     - device: '192.168.1.18'
>       persistence_file: 'path/mysensors3.json'
>       tcp_port: 5003
>     - device: mqtt
>       persistence_file: 'path/mysensors4.json'
>       topic_in_prefix: 'mygateway1-out'
>       topic_out_prefix: 'mygateway1-in'
>   debug: true
>   optimistic: false
>   persistence: true
>   retain: true
>   version: 2.0

the Solution is to use appdaemon

it works perfectly for that needs and “out of the box”

I followed the instructions here AppDaemon

and i was up and running in 30 mins

did you end up using one of the examples? I have a similar setup with several rf switches that I would like to retain the state on reboot

Hey smolz,

I resigned having it done by HA directly and installed/configured AppDaemon

This one works really well, even for non coder, they provided an example py script exacly for what i wanted to do.

I’m all set now and working :slight_smile:

have a look here : https://github.com/home-assistant/appdaemon

Good luck

It seems weird that I would need to do this just to keep track of a light switch. I have 5 RF outlets that are for living room and upstairs lights. I may just start to replace those with wemo or tp-link outlets since the couple of those I have appear to keep their state through a restart.