Announcement: AppDaemon 1.3.4

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
  • Fix a bug that overwrote state attributes
  • Fix to smart heat example app
  • Fix day constraints while using time travel

Breaking Changes

None

2 Likes

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.

Any suggestions?

Thanks

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?

That’s not right - anything in the error log?

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?

in /home/pi/appdaemon/Temp/switches.db

There is a switches.db there that contains data.

What does

$ ls -l /home/pi/appdaemon/Temp/switches.db

return? And you didn’t say if there were any errors in the error log or not …

Haha, your faster then I can type. Nothing new (after 21:17) in the error log

See below. Also changed to the dir and did a dir as the ls gave an error. Look at the filename when I do a dir. Is that normal?

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.

Heh, traveling myself this week - on a plane now.

At the moment you can’t pick and choose, but that might be a good enhancement - i’ll take a look at adding it.

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.

Any suggestions how to deBug?

What error did ls give? i want to see the permissions on the file and the only way to d that. Linux is ls -l

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.

OK, so the db is owned by root - what user are you running hass with?

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.

For completeness added content of config

OK, lets try some debugging -

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)?

OK, can you once again send me the output of ls -l /home/hass/.homeassistant/TempApp/*

I can only think this is a permissions problem but I am not sure why it is happening …