I am so sorry in advance. I have read the forums and tried many examples but I either get errors on the template editor, or that works, then errors in the yams on check, I move stuff around, get a clean yaml, then the sensors dont appear. I am two hours in and ready to give up for another day…
So… I have a current cost sensor working and providing two values - power_now_cc and solar_generation_cc. These entities are providing values. I wish to create two new sensors that will be “Exporting Power” and “Importing Power” based on the above - however the exporting power I want set to 0 if it is a negative.
My existing sensors (working fine) -
- name: "Power Now - CC"
unit_of_measurement: 'W'
state: '{{ state_attr("sensor.current_cost", "Appliance 0") * 0.9533 | round(0) -300}}'
device_class: power
state_class: measurement
- name: "Solar Generation - CC"
unit_of_measurement: 'W'
state: '{{ state_attr("sensor.current_cost", "Appliance 1") * 0.9533 | round(0)}}'
device_class: power
state_class: measurement
From this forum, I have tried multiple options but I cant get any to work. My best ones are these below which work fine in the template developer tools and give correct results, but when added to the template sensor block, they pass the yaml test, I do the restart and all my other sensors stop working - so I comment these out, restart and the others all start working again. I guess I have something wrong in the syntax which is working in dev tools, no yaml error -
- name : "Importing Power"
unit_of_measurement: 'W'
value_template: >-
{{ [0, states('sensor.power_now_cc') | round - states('sensor.solar_generation_cc') | round] | max }}
device_class: power
state_class: measurement
- name : "Exporting Power"
unit_of_measurement: 'W'
value_template: >-
{{ [0, states('sensor.solar_generation_cc') | round - states('sensor.power_now_cc') | round] | max }}
device_class: power
state_class: measurement
The dev tools is good -
-
name : “Importing Power”
unit_of_measurement: ‘W’
value_template: >-
0
device_class: power
state_class: measurement- name : "Exporting Power" unit_of_measurement: 'W' value_template: >- 433 device_class: power state_class: measurement
Where am I going wrong ?