I 've been using AD for a while now, and use extensive use of YAML files for the inputs. I just ran into an issue i can’t explain. To check it out, i created the following test code and YAML file:
Test code followed by the YAML file:
import appdaemon.plugins.hass.hassapi as hass
import datetime
import inspect
class TestYamlRead(hass.Hass):
def initialize(self):
# Only executes the yaml read function
self.read_data_from_yaml()
def read_data_from_yaml(self):
self.motion_dict = {}
self.motion_dict = self.args["motion_actions"] #Read data from "motion_actions" section
self.log("set motion_dict: {}".format(self.motion_dict)) # Print to the log
for motion in self.motion_dict:
if "countdown_sensor" in self.motion_dict[motion]:
self.motion_dict[motion]["countdown_sensor"] = "sensor."+self.motion_dict[motion]["countdown_sensor"] # Update "countdown_sensor" entry with the word "sensor." I use the same name to create a binary_sensor., which is why i do it this way
motion_sensor_actions_test:
module: test_yaml_read
class: TestYamlRead
dependencies: []
motion_actions_test:
motion_training_room_ksc_long:
motion_sensor: binary_sensor.training_room_motion_sensor
on_action: toggle_scene
countdown_sensor: timer_training_room
delay: 120
Here’s the strange part. Whenever i edit the py file, an additional “sensor.” gets added to the beginning of countdown_sensor. The log output from simply adding a space and resaving the py file is:
motion_sensor_actions_test: set motion_dict: {‘motion_training_room_ksc_long’: {‘motion_sensor’: ‘binary_sensor.training_room_motion_sensor’, ‘on_action’: ‘toggle_scene’, ‘countdown_sensor’: ‘timer_training_room’, ‘delay’: 120}}
#2:
motion_sensor_actions_test: set motion_dict: {‘motion_training_room_ksc_long’: {‘motion_sensor’: ‘binary_sensor.training_room_motion_sensor’, ‘on_action’: ‘toggle_scene’, ‘countdown_sensor’: ‘sensor.timer_training_room’, ‘delay’: 120}}
#3:
motion_sensor_actions_test: set motion_dict: {‘motion_training_room_ksc_long’: {‘motion_sensor’: ‘binary_sensor.training_room_motion_sensor’, ‘on_action’: ‘toggle_scene’, ‘countdown_sensor’: ‘sensor.sensor.timer_training_room’, ‘delay’: 120}}
So it seems that the self.args[] is staying in-sync with the motion_dict, even though it’s re-read each time. I added the line self.args.clear to try and clear it out, but that didn’t do anything (just added another sensor. to the beginning). The same behavior occurs if I add anything to the motion_dict - it is then mirrored in self.args.
Anyone know what is going on? I can work around it, but I like this method a little better.