Hi, I’ve been struggling with custom sensors in template in yaml for a few days now. They are still unavailable even though they work correctly in Developers tools-templates.
This is the last one in the listing from the “PV power min” sensor.
The latter are dependent on “PV power min”. They work fine for me in the beginning. I can’t figure out what’s wrong.
I guess I’m making a mistake in the boolean operations.
Thanks for any help.
template:
- sensor:
- name: "PV suff"
unit_of_measurement: "W"
unique_id: pv_sufficient
state: >
{% set PV_suff = ( states('sensor.PV_power')|float(default=0) - states('sensor.house_consumption')|float(default=0) ) |float(default=0) %}
{{ PV_suff|float(default=0) }}
- sensor:
- name: "On grid now"
unit_of_measurement: "W"
unique_id: on_grid_now
state: >
{% set On_grid_now = states('sensor.on_grid_l1_power')|float(default=0) + states('sensor.on_grid_l2_power')|float(default=0) + states('sensor.on_grid_l3_power')|float(default=0) %}
{{ On_grid_now|float(default=0)|int }}
- sensor:
- name: "Shelly power 3f"
unit_of_measurement: "W"
unique_id: shelly_pw_3f
state: >
{% set Shelly_PW = states('sensor.shelly_boiler_channel_a_power')|float(default=0) + states('sensor.shelly_boiler_channel_b_power')|float(default=0) + states('sensor.shelly_boiler_channel_c_power')|float(default=0) %}
{{ Shelly_PW|float(default=0) }}
- sensor:
- name: "PV power min"
unique_id: pv_min_pw
icon: mdi:water-boiler-auto
state: >
{% set B_2kW = 2000|int %}
{% set pv_min = PV_suff|int >= B_2kW|int %}
{{ pv_min|int }}
- sensor:
- name: "Boiler 2kW ON"
unique_id: Boiler_2kW_ON
icon: mdi:water-boiler-auto
state: >
{% set HCx = 1.15 | float %}
{% set B_2kW = 2000 | int %}
{% set B_4kW = 4000 | int %}
{% set HCx_pw = ( states('sensor.house_consumption') | float * HCx | float ) | float | int %}
{% set Boiller_2kW = ( (PV_suff | int >= B_2kW | int) and (PV_suff | int < B_4kW | int) ) | int | default(0) %}
{{ Boiller_2kW | bool }}
- sensor:
- name: "Boiler 4kW ON"
unique_id: Boiler_4kW_ON
icon: mdi:water-boiler-auto
state: >
{% set HCx = 1.15 | float %}
{% set B_4kW = 4000 | int %}
{% set B_6kW = 6000 | int %}
{% set HCx_pw = ( states('sensor.house_consumption') | float * HCx | float ) | float | int %}
{% set Boiller_4kW = ( (PV_suff | int >= B_4kW | int) and (PV_suff | int < B_6kW | int) ) | int | default(0) %}
{{ Boiller_4kW | bool }}
- sensor:
- name: "Boiler 6kW ON"
unique_id: Boiler_6kW_ON
icon: mdi:water-boiler-auto
state: >
{% set HCx = 1.15 | float %}
{% set B_6kW = 6000 | int %}
{% set HCx_pw = ( states('sensor.house_consumption') | float * HCx | float ) | float | int %}
{% set Boiller_6kW = (PV_suff | int >= B_6kW | int) | int | default(0) %}
{{ Boiller_6kW | bool }}
- sensor:
- name: "House consumption without boiler"
unit_of_measurement: "W"
unique_id: hc_wo_boiler
state: >
{% set HC_wo_b = ( states('sensor.house_consumption') | float - Shelly_PW | int ) | float | int %}
{{ HC_wo_b | int }}