Oh, my docker container is still in version 2023.8.2. Looking forward to the upgrade!
I think we are (mostly) hoping to have this facilitated in YAML and the UI.
If I create a template sensor in the UI (or in YAML)
e.g. 'sensor.t_motion_shower_02_battery_is_available'
based on a single 'sensor.motion_shower_02_battery'
my new template sensor does not appear on the device page for the device to which ‘sensor.motion_shower_02_battery’ belongs…
It gets its own page in the UI, but it is associated (linked to) the template integration
I would like to have some way of getting it to appear as an additional sensor on this device page (the device page to which the source sensor belongs)
+1 same, i’m relatively new to HA and found this thread while searching how to associate a template sensor to a parent device. Same situation as someone else where zwave blinds state is unknown and i created a template sensor to be based off a 0-100 value that represents the tilt.
All of this really should be possible. Manually defined MQTT entities have been able to do this for a while now.
Exactly. Much like manually defined MQTT entities, one should be able to define the device to which a template entity belongs.
Here is an example of something that I just created:
mqtt:
climate:
- device:
identifiers: ["house.air_conditioner"]
name: Air Conditioner
manufacturer: Daikin Industries, Ltd.
model: FTXA35BS
name: Thermostat
... # Other configurations here
template:
- sensor:
- name: "Air Conditioner Current Temperature"
state: "{{ state_attr('climate.air_conditioner', 'current_temperature') }}"
unit_of_measurement: "°C"
device_class: "temperature"
# This is the feature request: the ability to set the entity's device.
# As of now, this will not work (do not try at home).
device:
identifiers: ["house.air_conditioner"]
This would allow for adding template entities to devices, grouping them all together.
The same syntax proposed for the MQTT integration could be used:
+1
Being able to associate entities with devices in yaml would be very useful. I have an immediate need to do this with history_stats sensors and trigger-based template sensors & binary_sensors.
Also in need of this, I bought some cheap temperature and humidity sensors that work mostly OK but they clearly have an offset compared to other better quality sensors. I’d like to hide the sensor’s “raw” value and expose the templated sensor as the visible entity.
I would like to see this functionality as well. I have lock that the battery percentage is wrong (maybe coz Im using rechargeable). It also gives the Voltage, so I template to convert the Voltage to percentage based on the rechargeable battery voltage. It fix the problem well, but would be nice to have that entity in the device page.
+1 on this is. It is so annoying to have to manually search for entities that are made out of entities from only one device and can’t be found under that device
I’ve crafted an attempt at this on ✨ Link template and devices · kamaradclimber/home-assistant@9a92b96 · GitHub.
It works by creating a device for each template defined through the UI. The device is then connected to the relevant device (if all entities referred by the template are from the same device).
The main device has backlinks to all templates:
Each template device has a link to the main device:
This is not as clean as I’d like to (mostly because it creates intermediate devices that make no real sense) but it’s a start.
I’ve created Add template sensors to device page · home-assistant/architecture · Discussion #1054 · GitHub to track the discussion about how it could be implemented in HA.
And a better proof of concept with ✨ Directly connect templates with relevant device · home-assistant/core@dac3f9c · GitHub.
It now connects directly template and the most relevant device.
Thanks …
I’m greatly encouraged by your positive action in providing a proof-of-concept to address this issue.
I was looking at the issue again today and was thinking that I would end up using Frenck’s (also proof of concept) labels feature to tag everything (all existing device entities and my derived entities) with a label to represent a virtual (virtual) device that could group everything related together.
I really hope we can get some movement to be able to make these associations…
Here comes a (very long) side-note…
However, for me, this is a bit of an XY_problem
MQTT sensors (which can be linked to devices), single entity templates being linked to the device of the entity they reference all seem secondary to the question…
“Why do I need to create so many template sensors in the first place?”
It’s mostly system optimization. (almost want to ping bdraco here )
As I mentioned in my earlier post, the vast majority of my template sensors exist solely to
- control the precision I actually care about having stored in the database
- Temperature sensors that report 3-4 decimal places
- Light sensors that report curtains shifting in the breeze
- control the update frequency I actually care about having stored in the database
- Plugs reporting atomic power fluctuations or updating 2-4 times a second when in use
- control how significant the change should be for me to even consider recording it
- Is it significant that my longitude changed from -123.52426978 to -123.52427128?
- control the throttling and normalizing of values
I know that having any of these abilities/directives addressable on the entities themselves could more than halve the number of templates I have, halve my CPU use and reduce my IO and storage by orders of magnitude
I have pursued the creation of filter entities (not yet in the UI) and template sensors using appdaemon to generate YAML entity replacements that are mostly aimed at reducing CPU and Database IO to keep my system functioning as responsively as possible.
Most of them are just rounding to integers or half integers (we have some rounding for display precision, but cannot do rounding for storage precision).
I have all of my LUX sensors find where they fall within predefined LUX Ranges that represent real life values that mean something to me and prevent every ±1 lx change from ending up in the database.
These two used to clock up about 25k rows of data per week, now down to 900
Another huge group removes insignificant GPS accuracies and insignificant (to me) GPS precision being recorded in the database. Before these optimizations, I could sit at my desk all day with occasional trips to the bathroom and still clock up a few thousand database entries on my person.teskanoo entity per day.
Some supporting data
+1
I have a fan entity and I want to expose the current fan percentage on the device page via this helper:
{{ state_attr(“fan.fornuftig_fan”, “percentage”) }}
I want this to show up on the device page
I believe that will now work if you create the temple sensor through the UI
how can I do this WITHOUT the UI? All my templates are nicely created in YAML and I would like to associate it to the devices (similar to the template helper…)
This is exactly my issue.
Yes! I want to have a integration called “my devices” and within that make my own device out of entities, template or otherwise…
So
Integration: My device
- Device:
Name: driveway monitor
Entities:- Section: Sensors
- binary_sensor.yolink-driveway-motion
- binary_sensor.template-mailbox-status
- Section: Config
- more templates related entities
And so on.
- more templates related entities
- Section: Sensors
So much easier to organize than pages of labels.
And if you could add sensors to a device in a different real integration, you could do very basic useful things like add a door sensor right to the lock device page…. Where it clearly belongs in my humble opinion.
Before labels, excel sheets… and labels are better, but it still just creates tons of table and new organization requirement to pack all the related templates and entities together in their logical “single device” logical use. I had excel tables of related entities, now I have lists of “Pack - driveway monitor”-type Labels…. Just adding them to a device would eliminate All of this.
take a look at the integration Device Tools
you can merged devices, create new one’s and assign entities to them.
Interesting Find. It certainly is aimed at the same general target. Looks a little more hack like from some of the issues discussion than I am willing to risk. Ghost Devices with no entities I cant get rid of seems unattractive. Curtailing promising if it’s still being worked on. Thanks