Hi everybody.
I am quite new to appdaemon and python but I would like to set a entity state (whitout calling services) in appdaemon according to the entity state I receive from an xml .
the xml I receive is like
<record>
<dato0>22</dato0>
<dato1>1</dato1>
</record>
<record>
<dato0>33</dato0>
<dato1>0</dato1>
</record>
where dato1 identifies the id of the switch and dato 0 the on/off open/closed status of switch or cover.
I would like to loop into the switches/cover entities and change the status matching the unique_id of the entity that contains the device_id in its name definition.
here my switch definition example:
mqtt:
switch:
- unique_id: sw_22
name: "luce cameretta"
state_topic: "/00:1a:4e:1b:33:6f/devices/lights/22/state"
command_topic: "/00:1a:4e:1b:33:6f/devices/lights/22/state"
payload_on: "1"
payload_off: "0"
optimistic: false
qos: 0
icon: hass:lightbulb
I am using appdaemon and I would like to set the entities status reading the value from xm, looping through the lights/cover dictionary, with a sentence like :
self.set_state(expected_unique_id, state=stato)
where expected_unique_id is the value that I would like to capture from the entity definition (i.e. unique_id) and stato is the on/off closed/open state of the entity
I tryed to debug the code with :
self.log("*********debug*********\n")
entity_info = self.get_state("switch.luce_cameretta", attribute="all")
unique_id = entity_info.get('attributes', {}).get('unique_id', None)
self.log(str(unique_id))
but the code return <class ‘NoneType’> in the log.
hopefully I was clear …
can anyone help me?
Thank you