Restore "switch" status after restart HA

I run HA 0.32.3 on an Pi 3 with “all in one installer”

I have noticed that the switch status is not restored after a restart/reboot of HA.

This happened for me, with all switches on Pilight and all “switches” for the automation.

  • all Pilight switches always shown as “off” after restart
  • all Automation “switches” always turned on after restart.

I don’t no if this was a bug or a missing feature :slight_smile:

Same issue here

I had the same issue. A page refresh was a workaround.

What do you mean with “page refresh”

The switch status is not restored after restarting HA at the moment there is another feature request somewhere. If you lights/ switches support state reporting then they should populate their status shortly after restart.

In a browser when viewing HA reload/refresh the page and this then displayed the switches OK. Sorry if this was not clear.

Ok I no what you mean. But this doesn’t help for me.

@nbittmann My switches get no receive state. But this problem is for the automation toggles, too.

I do not find any other requests like this.

Pls upvote the my first thread

I have made a component that does what you want:

1 Like

Thx looks great.

I have a problem to get it running.

  1. I created a folder named “custom_components” in config folder
  2. I created a file inside named “restore_states.py”
  3. Copied your hole code inside the .py
  4. Added restore_states: to the configuration.yaml

But after restart, HA doesn’t comes up and no log is created.
Is there anything else to do?

That is exactly what you should do.
If there is no errors in the log, i do not know what to suggest.

Hm that is strange…

There is completely nothing in the log.

Do you test this on HA lower than 0.33?

No, made it to day, so only tested with 0.33

Hm…updated to 0.33 but still not working and no log. Dont know whats going on :frowning:

Hi @Danielhiversen

Today I tried this again. In the systemd log I can see this error. Maybe there is something wrong with the last line?

Nov 25 02:44:16 raspberrypi hass[5043]: File "/home/hass/.homeassistant/custom_components/restore_states.py", line 98
Nov 25 02:44:16 raspberrypi hass[5043]: return True
Nov 25 02:44:16 raspberrypi hass[5043]: ^
Nov 25 02:44:16 raspberrypi hass[5043]: SyntaxError: 'return' outside function
Nov 25 02:44:17 raspberrypi systemd[1]: home-assistant.service: main process exited, code=exited, status=1/FAILURE
Nov 25 02:44:17 raspberrypi systemd[1]: Unit home-assistant.service entered failed state.

Ok found the error. 4 missing blanks^^ dont know what happened, I copied the hole file 10 times:-)
The component is now loading correct but my pilight stats are not restored :frowning:

I found this in the log. Hope this helps.

 Nov 25 04:31:03 raspberrypi hass[5236]: INFO:homeassistant.bootstrap:Setting up restore_states
Nov 25 04:31:03 raspberrypi hass[5236]: INFO:homeassistant.core:Bus:Handling <Event component_loaded[L]: component=restore_states>
Nov 25 04:31:04 raspberrypi hass[5236]: INFO:homeassistant.bootstrap:Setting up group
Nov 25 04:31:04 raspberrypi hass[5236]: INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: entity_id=group.default_view, old_state=None, new_state=<state group.default_view=off; entity_id=('group.wohnzimmer', 'group.jalousien', 'group.jalousie_hwr', 'sun.sun', 'sensor.time', 'camera.kamera_einfahrt', 'scene.aktiviere_alarm', 'scene.deaktiviere_alarm', 'sensor.mac_mini_tv', 'switch.brunnenpumpe', 'switch.drucker', 'switch.lichterkette', 'switch.fibaro_system_fgs212_switch_3kw_switch_3_0'), order=3, hidden=True, friendly_name=default_view, view=True @ 2016-11-25T05:31:04.011279+01:00>>
Nov 25 04:31:04 raspberrypi hass[5236]: INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: entity_id=group.media_player, old_state=None, new_state=<state group.media_player=unknown; entity_id=('media_player.rasplex', 'media_player.mobil', 'media_player.wohnzimmer'), order=4, hidden=True, friendly_name=Mediaplayer, view=True @ 2016-11-25T05:31:04.015258+01:00>>
Nov 25 04:31:04 raspberrypi hass[5236]: INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: entity_id=group.wohnzimmer_view, old_state=None, new_state=<state group.wohnzimmer_view=unknown; entity_id=('group.wohnzimmer',), order=5, hidden=True, friendly_name=Wohnzimmer, view=True @ 2016-11-25T05:31:04.019102+01:00>>

I tried a bit more.

The component works for me for the Automation toggles perfect, but not for the switch added with pilight component. So maybe its a problem with pilight?

Nice work Daniel, it is working. Thanks for the work! :grinning:

There is now an official version coming: https://github.com/home-assistant/home-assistant/pull/4614

1 Like

Always good, no more tweaking, but something that direct working.
That is minimise the error ratio. Thanks for sharing.

Not sure if I should wake this thread up or create a new one. But I still have the issue descriped in the OP, should I do anything to activate this funcion?

Unfortunately my switches (433mhz outlets and door sensor if that matters) doesn’t keep their state after reboot either. I tried the restore_state.py from some months ago in this thread. The log doesn’t show any error and the file seems to load just fine (pycache created and if I remove the file it doesn’t understand restore_state: in the config).
If this cant be solved, is there a way to use automation to update just the switch state value, without sending the command? In that case I can take the long way around and have like a input_boolean with the same value or something.
Best way were to just keep the value after a restart though :smile: