Does anyone know if it’s possible to retrieve the zone where a sensor is in a script or a template ?
I added different zone in my house, like kitchen, room children 1, bathroom, … and to this differents zones the devices created by mqtt integration.
I want to do a resume of all temperature sensors I have in a script and send it in a notification. For example I want my script return :
Resume Temp
Room children 1 : 19.8°C - 45.3%
Kitchen : 19.8°C - 45.3%
Bathroom : 19.8°C - 45.3%
I found how iterate over all sensors and keep only those ending with _temperature for example. I can get the state value. But I’m unable to access the zone name to display it in my message.
I tried in a python script :
for e in hass.states.entity_ids():
if e.startswith("sensor.temp") and e.endswith("_temperature") :
logger.warn("Entity : %s", e)
logger.warn("State : %s", hass.states.get(e))
But there is no attribute that refer the device where the sensors is or the area_id.
The goal is, when I add a new temperature sensor, I have nothing to do except add it in an area and my message let appear the new zone temperature. No template to modify or something else.
Ah ok , thanks, but I don’t see anything about area in sensors attributes. Can I retrieve area from anywhere ? Get all sensors in an area ? Or get Area from a sensor ?
The answer to all three questions is no. Currently, area is inaccessible to templates. All you can currently do with an area is to use it as the target for a service call (for example, turn on all lights in a given area).
It’s possible to have dynamically-created groups. For example, the following automation is triggered on startup and whenever the group.reload service is called. It selects all sensors whose device_class is temperature and adds them to a group called group.temperature_sensors.