Hi!
Did some googling, but didn’t find an easy solution. But I bet there is:
When I restart homesever, default state for the location of our family members is ‘not_home’.
But when I restart the homeserver, I almost always am at home.
Is there a way to set the default state after restart to ‘home’ - or even better, have the last state saved at restart? (also true for other switches… I have some mqtt switches always show as off after restarts)
I know that work continues on storing and restoring states but nothing has made it to a release yet. The only thing I can think of at the moment would be to set states in an automation that is triggered by the homeassistant start up event.
EVENT HOMEASSISTANT_START
Event homeassistant_start is fired when all components from the configuration have been intitialized. This is the event that will start the timer firing off time_changed events.
thank you. Now I have to find out how that works… (hass is huge, but documentation is sometimes a little sparse)
You use the event as a trigger for your automation, then in the actions you can set the states.
But in thinking about this more, you might be better served by using AppDaemon as there is already a mechanism in place to do this:
Call me stupid, but I can’t get it to work:
- alias: 'Hass start'
trigger:
platform: event
event_type: homeassistant_start
action:
- service: device_tracker.see
data:
dev_id: device_tracker.74d9cfd344074c4895ec693991a27d21
location_name: 'home'
- service: device_tracker.see
data:
dev_id: device_tracker.b7010ef5148b4455965f95bc74b2c405
location_name: 'home'
- alias: 'Licht ein wenn Sonne untergeht'
that’s what I tried. I have a group consisting of those device trackers, nicest would be if I could just set the state of ‘group.family’ to ‘home’.
I don’t think that service can set the state; I’m thinking - especially due to the name - that all it does is returns the current state. I don’t set states via automations except for some input_selects, which has a clear select_option service. So I haven’t really tried this.
That’s why I was saying AD may be a better solution.
Hi!
Hmm, sometimes things that seem to be so easy are very complicated… who’d think it’s not easy to just set a state?
AD… I’m still struggling with the possibilities and syntax of hass, now you’re sending me off to a whole new world… ok, I guess there’s no escape. But regardig saving the states, I haven’t seen that in the description page, am I to program that myself?
I know, but there’s really no avoiding it if you want to overcome limitations in HA like this. I’m no dev, but I have it running and now I’m getting more involved because AppDaemon is what runs HA Dashboard v2. It’s incredibly flexible and a guy like you will probably take to it much faster than someone like me. And there are a lot of people who have gone from automations in HA to everything automated from AD, so there is plenty of people to help.
Just not me - too much - at the moment as I am still learning myself. If you know Python though, you’ll be right at home. And @aimc has me busy with HADashboard skinning so I’m trying to squeeze it in between getting back on point with my CSS skills!
As for your second question; when you install AppDaemon, there are a number of example apps in the /appdaemon/conf/examples directory and the one you are looking for is switch_reset.py. You move that into your apps directory and configure it.
I think you’ll get a lot out of it.
OK OK I’ll have a look at it. first I started with homebridge, then I added homeassistant, moved modules back and forth… went from a raspi pi to a mac and then to a linux, the raspi still uses gpio to control the gate… OK, let’s start the next adventure. And no, I don’t think I’ll be faster than you and I don’t really know Python.
Now I’m getthing this:
2017-02-23 21:18:16.932500 INFO Loading Object switch_reset1 using class SwitchReset from module switch_reset
2017-02-23 21:18:16.932873 WARNING ------------------------------------------------------------
2017-02-23 21:18:16.933092 WARNING Unexpected error during loading of switch_reset1:
2017-02-23 21:18:16.933286 WARNING ------------------------------------------------------------
2017-02-23 21:18:16.934490 WARNING Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/appdaemon/appdaemon.py", line 996, in read_app
init_object(name, class_name, module_name, config[name])
File "/usr/local/lib/python3.5/dist-packages/appdaemon/appdaemon.py", line 690, in init_object
conf.objects[name]["object"].initialize()
File "/home/cs/.homeassistant/conf/apps/switch_reset.py", line 22, in initialize
self.device_db = shelve.open(self.args["file"])
File "/usr/lib/python3.5/configparser.py", line 1230, in __getitem__
raise KeyError(key)
KeyError: 'file'
Ah: I just found out, you need to specify a ‘file’ where the states are saved to. AND you need to specify a delay, too.
It’s saving the state of the tracker now, great. Only the state of some mqtt controlled lights is still reset (that must be another problem)
Hi!
That means the saving will in the next release of homeassistant? Sorry to sound noob, but I have no idea whether that is a forked and independet version or just the ‘dev’ version or whatever.
It will be part of the next release of homeassistant, that will be released this weekend.
OK, I’m having a perfect timing in that case, as always
If you still want to investigate appdaemon - and I can’t see a reason not to - repost your error message above into a separate post in the AD forum category so you’ll get the proper response.
Hi! I already posted the solution to avoid that error at the end of the message.
Sorry - modding threads and replying to others. I missed it first time round. Just didn’t want to leave you hanging.