I am attempting to read my tesla powerwall load power, then dividing this number (60/40) to then feed this number into my two solaredge inverters to have my solar production load follow my household load.
Just cant get the following code (in configuration.yaml) to return a value. I can see them in developer tools / states but state is always unknown.
My code seemingly is incorrect - can anyone assist with correcting the code?
template:
sensor:
name: inverter_1_load
state: >
{% set house_load = states(‘sensor.home_9_charles_load_power_2’) %}
{% if house_load is number %} # Check if it’s a number
{{ (house_load | float * 0.6) | round(0) }}
{% elif house_load is none %} # Check if it’s None
0 # Default value if None
{% else %} # all other cases such as unavailable, unknown or strings
0 # Default value if not a number
{% endif %}
unit_of_measurement: “W”
name: inverter_2_load
state: >
{% set house_load = states(‘sensor.home_9_charles_load_power_2’) %}
{% if house_load is number %} # Check if it’s a number
{{ (house_load | float * 0.4) | round(0) }}
{% elif house_load is none %} # Check if it’s None
0 # Default value if None
{% else %} # all other cases such as unavailable, unknown or strings
0 # Default value if not a number
{% endif %}
unit_of_measurement: “W”
template:
- sensor:
- name: inverter_1_load
state: >
{% set house_load = states('sensor.home_9_charles_load_power_2') | float %}
{% if house_load > 0 %} # Avoid division by zero
{{ (house_load * 0.6) | round(0) }} # 60% to inverter 1 (adjust as needed)
{% else %}
0
{% endif %}
unit_of_measurement: "W"
- name: inverter_2_load
state: >
{% set house_load = states('sensor.home_9_charles_load_power_2') | float %}
{% if house_load > 0 %} # Avoid division by zero
{{ (house_load * 0.4) | round(0) }} # 40% to inverter 2 (adjust as needed)
{% else %}
0
{% endif %}
unit_of_measurement: "W"
- sensor:
- name: Ainverter_1_load
state: >
{% set house_load = states('sensor.home_9_charles_load_power_2') %}
{% if house_load is number %} # Check if it's a number
{{ (house_load | float * 0.6) | round(0) }}
{% elif house_load is none %} # Check if it's None
0 # Default value if None
{% else %} # all other cases such as unavailable, unknown or strings
0 # Default value if not a number
{% endif %}
unit_of_measurement: "W"
- name: AAinverter_2_load
state: >
{% set house_load = states('sensor.home_9_charles_load_power_2') %}
{% if house_load is number %} # Check if it's a number
{{ (house_load | float * 0.4) | round(0) }}
{% elif house_load is none %} # Check if it's None
0 # Default value if None
{% else %} # all other cases such as unavailable, unknown or strings
0 # Default value if not a number
{% endif %}
unit_of_measurement: "W"type or paste code here
Thank you! This has solved the unknown state issue. Now I need to work out why the sensors always have a zero value. Obviously I have very little Jinja2 experience and am learning as I go…
Please consider marking my post above with the Solution tag.
It will automatically place a check-mark next to the topic’s title which indicates to others that the topic has been solved. This helps users find answers to similar questions