Hello! I just installed a Refoss home energy monitor and integrated it into my HA install. It was painless.
I was not happy with a lot of the default entity names that my Refoss created, and further, I wanted to combine some for split phase (e.g., my 240v items - I’m in north america). So, I thought I would just go and write some YAML.
I got the YAML to work (grr - reload YAML in developer tools does not reload). But I’m hitting a few roadblocks and I figure I may be going about this the wrong way.
I posted a sample of my YAML below. I see that for items I made I cannot edit them in the GUI (strange I cannot give myself unique IDs, but okay). I also cannot seem to assign an “area” to them - my HA dashboard is auto-created for me and I want them in their proper places.
I did some searching but mostly found bad tutorials. ChatGPT kept spewing garbage. Does anyone have a resource they could point me to to help me understand how I can integrate my custom templates better? Thanks!
I’m not sure what you mean there. I checked and you can add unique id’s in yaml. I don’t use them in my setup but I just added one to a template sensor and worked as expected.
No, as an end-user, you cannot add a unique ID to an entity that doesn’t have one. Unique IDs are a feature that must be provided by the integration itself.
The template integration can provide a unique id. It is up to you to specify it though.
- name: "EV Charger" # will still make sensor.ev_charger but will look nicer in your cards
unique_id: e9971788-f98f-43a2-bcfe-721f60f5c71d
unit_of_measurement: "W"
state: >
{{ (states('sensor.em16_a2_power')|float + states('sensor.em16_b2_power')) | round(1) }}
availability: >
{{ has_value('sensor.em16_a2_power') and has_value('sensor.em16_b2_power') }}
attributes:
amps: "{{ states('sensor.em16_a2_current') }}, {{ states('sensor.em16_b2_current') }}"
voltage: "{{ states('sensor.em16_a2_voltage') }}, {{ states('sensor.em16_b2_voltage') }}"
pf: "{{ states('sensor.em16_a2_power_factor') }}, {{ states('sensor.em16_b2_power_factor') }}"
energy: "{{ states('sensor.em16_a2_this_month_energy') }}, {{ states('sensor.em16_b2_this_month_energy') }}"
You can use any unique value. VSCode has a UUID generator, or you can use this, https://www.uuidgenerator.net/ or you can use the entity_id as that has to be unique too.
I wasn’t sure if the etiquette here was to edit prev. post or to keep posting. Apologies for all the followups.
So now I have two questions
when editing configuration.yaml I am happily including another file where I keep these templates created. However, I would also like the integral sensors I am making (to create energy from power) to be in the same file. My understanding is that I cannot do this- I cannot simply include another configuration file, only replace a section such as sensor: or template:. Is there somehting I’m missing?
Why do I need to make my new sensors, which are derivatives of my underlying sensors, as “templates”? This makes me feel like I am creating something that can be re-used. I tried just making them as sensors but it didn’t like it. Any pointers to a page that explains what I am missing?
template is an integration. It supports sensors, lights, covers and more.
Confusingly light and sensor are also integrations that support platforms like Lifx, Hue, mqtt, etc… In the old days template was just another platform under other integrations like light and cover, etc…
Making it an actual integration has been a recent change. Being it’s own integration has some advantages, like the way it is organised in the frontend and probably development advantages too (guessing).
Beyond what Tom has explained about the integration, the term “template” in HA is usually just referring to something that uses of the Jinja2 templating language.
This is a fairly common misunderstanding. It is possible to use Jinja templating in HA to create reusable macros and constants.
These replies are helpful. I guess I should think of template: as jinja2: to access its features.
Also the language of calling those “sections” integrations helps me understand that they’re accessing plugins or modules or some such, so it makes more sense.