I’d like to define a template sensor which is calculated.
a scaling factor is used to manipulate it, and therefore I need to use a “power” function.
here my sample, which doesn’t work:
template:
- sensor:
- name: "LeistungMPP1"
unit_of_measurement: "W"
state: >
{% set mpp1 = states('sensor.power_MPP1') * pow(10, states('sensor.power_sunssf')) | float %}
{{ mpp1 }}
sensor.power_MPP1 and sensor.power_sunssf are available. sensor.power_sunssf can be -10 to +10
tom_l
May 12, 2022, 10:38am
2
{% set mpp1 = states('sensor.power_MPP1') * 10 ** states('sensor.power_sunssf') | float %}
1 Like
sorry. it doesn’t work either…
even if I just try to use:
{% set mpp1 = states('sensor.power_MPP1') * 10 ** 1 | float %}
the state is unavailable.
same for:
{% set mpp1 = states('sensor.power_MPP1') * 10 | float %}
it works only that way:
{% set mpp1 = states('sensor.power_MPP1') | float %}
Hellis81
(Hellis81)
May 12, 2022, 12:00pm
4
if pow is a correct syntax then this should work. (or use Tom’s syntax but add the | float
)
You need to convert each state from string to float before doing the math.
template:
- sensor:
- name: "LeistungMPP1"
unit_of_measurement: "W"
state: >
{% set mpp1 = states('sensor.power_MPP1') | float * 10 ** states('sensor.power_sunssf') | float %}
{{ mpp1 }}
tom_l
May 12, 2022, 12:03pm
5
1 Like