Appdaemon yaml config nesting

I’ve converted everything over to a .yaml config now. The update process was painless. Thank you very much.

Now my question:
In the past, against several people’s advice, I have used dictionaries in my cfg file to pass information into my apps. Now that we are under Yaml, can I nest that information like below or something?

Current config in yaml file

presence_control:
  class: presence_control
  module: presence_control
  tracker_list: '{"input_boolean.everyone_home":[1+2+4+8],
    "input_boolean.someone_home":range(1,16),
    "input_boolean.noone_home":[0],
    "input_boolean.masterishome":range(4,16)}'
  trackers: '[("device_tracker.xxxxx_xxxxx",1),
    ("device_tracker.YYYYY_YYYYY",2),
    ("device_tracker.ZZZZ_ZZZZZ",4),
    ("device_tracker.AAAAA_AAAAA",8)]'

presence_control:
  class: presence_control
  module: presence_control
  tracker_list: 
    - entity: input_boolean.everyone_home
        bits: 15
    - entity: input_boolean.someone_home
        bits: range(1,16)
    - entity: input_bolean.noone_home
        bits: 0
    - entity: input_boolean.masterishome
        bits: range(4,16)

if so, how do we read it now?

Yes, this is exactly the point and a huge reason for moving to YAML. When you specify a parameter like tracker_list you will end up with self.args["tracker_list"] being a python list with all of your entries in, if you use the correct YAML syntax - it couldn’t be easier :slight_smile:

You do need to pay some attention to yaml syntax though. A list would be like this:

  arg_list:
    - entry 1
    - entry 2
    - entry 3

A dictionary would be:

  arg_dict:
    entry1: fred
    entry2: jim

etc. You can also nest lists in dicts and the other way around for truly insane parameter structures :wink:

you mean a structure like this…

  targets: '{"light.master_light_level":{"triggers":{"light.master_light_level":{"type":"light","bit":32,"onValue":"on"},
                                                   "input_boolean.masterishome":{"type":"tracker","bit":1,"onValue":"on"},
                                                   "media_player.mbr_directv":{"type":"media","bit":8,"onValue":"playing"},
                                                   "input_boolean.mastermotion":{"type":"motion","bit":4,"onValue":2},
                                                   "input_boolean.master_alarm_active":{"type":"sensor","bit":64,"onValue":"on"}},
                                       "type":"light",
                                       "onState":[41,42,43,45,46,47,57,58,59,100,104,106,108,110,112,116,120,122,124,126]+list(range(61,97)),
                                       "dimState":[41,42,43,45,46,47,57,58,59,61,62,63,106,110,122,126],
                                       "ignoreState":[1,2,3,5,6,7,9,10,11,13,14,15,17,18,19,21,22,23,25,26,27,29,30,31,33,34,35,
                                                      37,38,39,49,50,51,53,54,55,97,98,99,101,102,103,105,107,109,111,113,114,115,117,118,119,121,123,125,127],
                                       "callback":self.light_state_handler,
                                       "overrides":["input_boolean.party_override"]},
            "light.master_fan_level":{"triggers":{"light.master_fan_level":{"type":"fan","bit":16,"onValue":"on"},
                                                  "sensor.master_temperature":{"type":"temperature","bit":4,"onValue":"on"},
                                                  "input_boolean.masterishome":{"type":"tracker","bit":1,"onValue":"on"}},
                                      "type":"fan",
                                      "onState":[4,5,6,7,12,13,14,15,20,21,22,23,28,29,30,31,36,37,38,39,44,45,46,47,52,53,54,55,60,61,62,
                                                 63,68,69,70,71,76,77,78,79,84,85,86,87,92,93,94,95,100,101,102,103,108,109,110,111,116,117,118,119,124,125,126,127],
                                      "dimState":[0],
                                      "ignoreState":[0],
                                      "callback":self.light_state_handler,
                                      "overrides":["input_boolean.party_override"]}}'

Each number is a binary mask. The dictionary structure is a pain in the back side but the code is simplicity itself.

Yes, that isn’t YAML but could be represented as YAML - that’s the beauty of YAML (I’m a recent convert!)

1 Like