Advertisement
bdnstn

Template error handling

Oct 1st, 2023
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 1.69 KB | None | 0 0
  1. template:
  2. #########
  3.   - sensor:
  4.     - name: "Excess solar" # Not strictly EXCESS - It's a guess, shows what solar is producing when nothing coming from the grid
  5.       unique_id: excess_solar
  6.       unit_of_measurement: "W"
  7.       device_class: energy
  8.       state: > # if solar is > 0 and house = 0 then publish solar else publish 0
  9.         {% if (states('sensor.solarman_output_active_power') != 'unknown')
  10.           and (int(states('sensor.solarman_output_active_power')) > 0)
  11.           and (int(states('sensor.house_power_consumption')) == 0) %}
  12.           {{ states('sensor.solarman_output_active_power') }}
  13.         {% else %}
  14.           0
  15.         {% endif %}
  16.     - name: "Weather factor"
  17.       unique_id: weather_factor # Factor for water time multiplier.
  18.       state: >
  19.         {% set ref_temp = 20 %}
  20.         {% set ref_rain = 10 %}
  21.         {% set temp_factor = 5 * ((((float(states('sensor.marybrook_temp_max_0'))) - ref_temp)) / 100) %}
  22.         {% set target_rain = ref_rain * (1 + temp_factor) %}
  23.         {% set likely_rain = float(states('sensor.marybrook_rain_chance_0'))/100 *
  24.           float(states('sensor.marybrook_rain_amount_min_0')) %}
  25.         {% if likely_rain < float(states('sensor.ibusse56_precipitation_today')) %}
  26.           {% set likely_rain = float(states('sensor.ibusse56_precipitation_today')) %}
  27.         {% endif %}
  28.         {% if likely_rain >= target_rain %}
  29.           {% set weather_factor = 0 %}
  30.         {% else %}        
  31.           {% set weather_factor = float((target_rain - likely_rain) / ref_rain) %}
  32.         {% endif %}
  33.         {% if weather_factor == 'unavailable' %}
  34.           {% set weather_factor = 1 %}
  35.         {% endif %}
  36.         {{ weather_factor }}
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement