Mainly bugfixes this time, but I have added a couple of new examples.
In particular, I wrote an App called “switch_reset” that will read and track the state of all input_boolean, input_slider and input_select and restore them when HomeAssistant restarts.
1.3.4 (2016-09-18)
Features
Add Moementary Switch example
Add Switch Reset Example
Fixes
Fix a several a race condition in App Initialization
Andrew, in the app to restore the states (Switch Reset); in the config example you refer to:
file = /etc/appdaemon/switches.db
When I add this (+the rest of the example) to the appdaemon.cfg it throws an error related to the .db so I assume it goes back to the location in the switches.db file above.
I searched the PI but could not find the switches.db file.
The path is created by the app, so you can put it anywhere - in the example it assumes you have created a directory for /etc/appdaemon which you probably haven’t - that’s just the way I have mine setup. You could put it in the same directory as your hass config if you wanted to.
Ok, that did the trick. App now running and saving state. However it seems to do only so at start of HASS.
In the log (of Appdaemon) it nicely shows that it saves all the states (see also screenshot log). When I then change the state of an input select and an input boolean (screenshot), wait a few min, then to a HASS restarts (sudo systemctl restart home-assistant.service) the log also shows it detecs a restarts but restores the original state not the LAST state I set. Am I missing some key step?
After the restart it seems it is rediscovering all the switches for the first time which means something went wrong with the db file - maybe it couldn’t write it or it got deleted somehow - where did you end up putting it?
I have changed the permissions of the file and starts looking better but at the airport now difficult to test in detail.
Other Q: Can you actually set which states it holds? Some sensors (for example owtracks) gets updated anyway so prefer not to restore state as actual states can change between (for instance) a restart or when the power goes off.
Mhhh, still having issues with this app. Still not saving state changes during running off hass. Restores only original states from when it ran the first time.
Not really giving an error (nothing ion the error logs). Screenshot ls -l below and screenshot Appdeamon log also attached. My logically would be a permission thing.
p.s. I know the error logs are working as there is stuff in there from when I was trying things from 5 days ago.
using the AIO installer. I have one user I login withy putty & winscp (user: PI). I think HASS itself uses user ‘hass’ as there are files with owner hass (file & grouo) in the home assistant directory.
With Winscp I can change ownership of files in .homeassistant (from eg root to hass) but in the Appdeamon dir I only have the option to change to ‘root’.
As you can see I’m not very deep into user/group thing of Linux.
AIO shouyld run it as the hass user, which means that AppDaemon probably can;t write to the file where you have it under the PI users home directory. Also, somehow it is now owned by root which makes matters worse.
Try starting again with the db file in the hass users home directory.
Ok, made subdir under .homeassistant with same rights at my scripts folders & files. .db files gets created and innitial states are stored and restored when restarting. However still no saving of states in between. Last .db update is from when the file was created.
Edit the app and look at line 41 - it should read:
#self.log_notify("State change: {} to {}".format(entity, new))
Remove the # making sure that the line is at the same indent as the line below.
When you save the file, AppDaemon should reload it and start logging any updates it gets so we can see if it is properly reacting. Then turn the switch on and off a few times and change the input_select then send me the logfile.
Ok, good news. Its logging the state changes so its something with writing to the database. Is it not strange that the db is called switches.db.db (2x .db)?