I know template sensors are often used to break out attributes into their own sensor but I would like a way to combine sensors into attributes. My use case is a Multisensor (motion, light, temp, etc). I want the main sensor to display motion and have attributes for the other sensors.
I would anticipate it working much like the MQTT sensor:
you want 1 sensor with several other sensor values as attributes.
in that case you use listen_state for the sensors involved and point them all to the same callback.
in the callback you get all involved states with get_state.
with set_state you set the state from your new sensor and its attributes.
ill show you some pseudo code:
def initialise(...):
self.listen_state(self.change_state,self.args["main_sensor"])
for sensor in self.args["attributes"]:
self.listen_state(self.change_state,sensor)
def change_state(...):
all_attributes = {}
statevalue = self.get_state(self.args["main_sensor"])
for name,sensor in self.args["attributes"].items():
all_attributes[name] = self.get_state(sensor)
self.set_state(self.args["new_sensor_name"], state=statevalue,attributes=all_attributes)
appdaemon code is completely different from python_script for HA.
so you probably rarely find AD code that can easy be changed to python_script for HA.
and i think that there are very little people who first used AD and then did go to python_script.