I’m on 74.2 and Appdeamon 1.3.0 and somewhere (not sure during which upgrade cycle) my switch_reset app stopped working correctly. Now getting below error in Appdeamon log.
Any ideas what is causing this change in behavior and how I can solve it? p.s. I’m not a writer of apps… I think I use this one from @ReneTode
Error in Appdeamen log:
File "/usr/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 1575, in init_object
init()
File "/config/appdaemon/apps/switch_reset.py", line 24, in initialize
self.device_db = shelve.open(self.args["file"])
File "/usr/lib/python3.6/shelve.py", line 243, in open
return DbfilenameShelf(filename, flag, protocol, writeback)
File "/usr/lib/python3.6/shelve.py", line 227, in __init__
Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback)
File "/usr/lib/python3.6/dbm/__init__.py", line 94, in open
return mod.open(file, flag, mode)
The config:
Switch Reset:
module: switch_reset
class: SwitchReset
#file: /home/hass/.homeassistant/switches
file: switchesnw
delay: 30
log: 1
The app:
import appdaemon.plugins.hass.hassapi as hass
import shelve
import time
#
# App to reset input_boolean, input_select, input_slider, device_tracker to previous values after HA restart
#
# Minimote can send up to 8 scenes. Odd numbered scenes are short presses of the buttons, even are long presses
#
# Args:
#
#delay - amount of time after restart to set the switches
#
#
# Release Notes
#
# Version 1.0:
# Initial Version
class SwitchReset(hass.Hass):
def initialize(self):
self.device_db = shelve.open(self.args["file"])
self.listen_event(self.ha_event, "ha_started")
self.listen_event(self.appd_event, "appd_started")
self.listen_state(self.state_change, "input_boolean")
self.listen_state(self.state_change, "input_select")
self.listen_state(self.state_change, "input_slider")
def ha_event(self, event_name, data, kwargs):
self.log_notify("Home Assistant restart detected")
self.run_in(self.set_switches, self.args["delay"])
def appd_event(self, event_name, data, kwargs):
self.log_notify("AppDaemon restart detected")
self.run_in(self.set_switches, self.args["delay"])
def state_change(self, entity, attribute, old, new, kwargs):
self.log_notify("State change: {} to {}".format(entity, new))
self.device_db[entity] = new
def set_switches(self, kwargs):
self.log_notify("Setting switches")
# Find out what devices are avaiable.
# If we don't know about it initialize, if we do set the switch appropriately
state = self.get_state()
for entity in state:
type, id = entity.split(".")
if type == "input_boolean" or type == "input_select" or type == "input_slider":
if entity in self.device_db:
if self.device_db[entity] != state[entity]["state"]:
self.log_notify("Setting {} to {} (was {})".format(entity, self.device_db[entity], state[entity]["state"]))
new_state = self.set_state(entity, state = self.device_db[entity])
else:
self.log_notify("Adding {}, setting value to current state ({})".format(entity, state[entity]["state"]))
self.device_db[entity] = state[entity]["state"]
def log_notify(self, message, level = "INFO"):
if "log" in self.args:
self.log(message)
if "notify" in self.args:
self.notify(message)