botfixer
(Botfixer)
January 15, 2023, 6:01pm
1
Hi, i am trying to setup a template sensor like this:
template:
sensor:
- name: Hausverbrauch
state: {{ states(‘sensor.sn_301456377_metering_power_absorbed’) | float(0) }}
In template editor, the preview windows shows the value needed.
But when integrate it into /config/configuration.yaml i get this error:
Error loading /config/configuration.yaml: invalid key: “OrderedDict([(“states(‘sensor.sn_301456377_metering_power_absorbed’) | float(0)”, None)])”
in “/config/configuration.yaml”, line 20, column 0
No idea what i am doing wrong.
thank you for help.
Seems ok but you might have slipped formatting … please format your config between 3 backtics (```)-
tom_l
January 15, 2023, 6:15pm
3
You need quotes around single line templates:
state: "{{ states('sensor.sn_301456377_metering_power_absorbed') | float(0) }}"
This is only copying an existing sensor state. Why?
1 Like
And now I am interested to know HOW you deducted this to be an existing sensor
tom_l
January 15, 2023, 7:26pm
5
?
All this template does is copy the state of the source sensor. You can’t template non-existent sensors. Therefor I assume it actually exists.
Ah… that way, I was thinking: why could this not be a template-sensor…anyhow…thx
botfixer
(Botfixer)
January 17, 2023, 2:50pm
7
Thank you very much. Works great now!
tom_l
January 17, 2023, 5:35pm
8
No problem. Can you explain why you need to duplicate the source sensor?
botfixer
(Botfixer)
January 18, 2023, 8:32am
9
Yes, sure.
There a two things about that,
I´m new to HA and still have to learn syntax
I am using the SMA Solar Integration (SMA Solar - Home Assistant ). It´s running fine instantly. Now, i want to use these entities in the Energy Dashboard. It looks like the dashboard display only entities with the device class: energy. But most of SMAs Integration Entities have device class: power, so i am not able to choose them.
So I thought it maybe make sense to copy the data value from the desired entity to a new template sensor. If I understood it correctly, I can define the device class myself for a template sensor.
I dont know if this is the right way.
tom_l
January 18, 2023, 9:05am
10
It’s one way of adding a state_class and device_class, but not the best way.
The best way is to open an issue for the integration. These classes should be present.
The other way to do it without creating a new entity is to use customize.
configuration.yaml
homeassistant:
customize:
sensor.sn_301456377_metering_power_absorbed:
device_class: energy
state_class: total_increasing
Or if you want to put all your customizations in a seperate file:
configuration.yaml
homeassistant:
customize: !include customize.yaml
customize.yaml
sensor.sn_301456377_metering_power_absorbed:
device_class: energy
state_class: total_increasing
1 Like
botfixer
(Botfixer)
January 18, 2023, 10:16am
11
ah, i am able to override existing sensors and give them a new class.
Thank you.
Not sure if the device classes of the SMA integrations are wrong. Maybe some entities must have the device class power.
I think it where better, when the energy portal does not filter the entities on device class energy.
But i ask the author.
I have read, that all Values for Energy Dashboard must be kWh or kW. My value are Wh or W.
I open an issue.
tom_l
January 18, 2023, 10:25am
12
It never allowed power sensors. It is an Energy dashboard, it only accepts energy sensors.
Changing your power device class to energy will not give you meaningful results. Power and energy sensors are very different things.
I use the SMA integration and all my Sunnyboy inverter sensors have the correct classes.
Wh or kWh is an energy sensor.
W or kW is a power sensor, you can not use this with the energy dashboard.
botfixer
(Botfixer)
January 18, 2023, 10:43am
13
yes, you are right.
I saw the dashboard as a real-time dashboard for the current consumption, just like it happens in the SMA app. But the dashboard refers to today’s generation for PV generation, house consumption and grid consumption.
Everthings is fine. Thank you again for your support.
botfixer
(Botfixer)
January 18, 2023, 10:47am
14
looks like this now:
Dont know if the sensor “metering_total_absorbed” is the right one for grid consumption, but i will see later.