Hi All, great component!
I’m relatively new to coding and HA. I know how to do past tense charting, more or less, but I wouldn’t know where to start to chart the forecast prices. Would any of you know where to start with this?
Also, for those that are interested:
I’ve taken a couple examples from this forum, plus some other data to produce these templates if anyone’s interested.
Light Power - see this link for a template i’ve put together for a Philips Hue LTW001, one for each globe: Manually calculating power consumption of lights - #25 by cloak
- platform: template
sensors:
living_room_big_lamp_power:
friendly_name: Living Room Big Lamp Power
icon_template: mdi:lightning-bolt
device_class: power
unit_of_measurement: "W"
value_template: >
{% if is_state('light.living_room_big_lamp','on') %}
{% set mired = state_attr("light.living_room_big_lamp","color_temp") %}
{% set brightness = ((state_attr("light.living_room_big_lamp","brightness") - 3) * (100 - 1)) / (254 - 3) + 1 %}
{% set m153 = (0.000435254 * (brightness**2) + (0.002105929 * brightness) + 1.500175321) %}
{% set m203 = (0.00057964 * (brightness**2) + 0.001134825 * brightness + 1.527090668) %}
{% set m253 = (0.000785198 * (brightness**2) - 0.002785236 * brightness + 1.57216088) %}
{% set m303 = (0.000733083 * (brightness**2) - 0.002574077 * brightness + 1.573079888) %}
{% set m353 = (0.000668279 * (brightness**2) - 0.001853391 * brightness + 1.561981489) %}
{% set m403 = (0.000570268 * (brightness**2) + 0.0000671178176666897 * brightness + 1.527920206) %}
{% set m454 = (0.000487813 * (brightness**2) - 0.000161527 * brightness + 1.518884275) %}
{% if mired >= 153 and mired < 203 %}
{{ ((((mired - 153) * (m203 - m153)) / (203 - 153)) + m153)|round(2) }}
{% elif mired >= 203 and mired < 253 %}
{{ ((((mired - 203) * (m253 - m203)) / (253 - 203)) + m203)|round(2) }}
{% elif mired >= 253 and mired < 303 %}
{{ ((((mired - 253) * (m303 - m253)) / (303 - 253)) + m253)|round(2) }}
{% elif mired >= 303 and mired < 353 %}
{{ ((((mired - 303) * (m353 - m303)) / (353 - 303)) + m303)|round(2) }}
{% elif mired >= 353 and mired < 403 %}
{{ ((((mired - 353) * (m403 - m353)) / (403 - 353)) + m353)|round(2) }}
{% elif mired >= 403 and mired < 454 %}
{{ ((((mired - 403) * (m454 - 403)) / (454 - 403)) + m403)|round(2) }}
{% elif mired == 454 %}
{{ m454|round(2) }}
{% endif %}
{% else %}
{{ 0.00 }}
{% endif %}
Customise Glob - change device class to power where applicable so next template sums all
"sensor.*_outlet_power":
device_class: power
Sum all power for device class 'power’
- platform: template
sensors:
sum_power_consumption:
friendly_name: "Power"
unit_of_measurement: 'W'
icon_template: mdi:power-plug
value_template: >
{{ states.sensor
| selectattr('attributes.device_class', '==', 'power')
| map(attribute='state') | map('float') | sum }}
Existing prediction templates from Github, new averages, and cost predictions
- platform: template
sensors:
amber_peak_predicted_2h:
friendly_name: "Amber 2 hour peak predicted"
unit_of_measurement: "¢/kWh"
value_template: >-
{% set forecast = states.sensor.amber_general_usage_price.attributes['price_forcecast'] %}
{% set highest = forecast[0:4] | sort(reverse=true, attribute='price') | first() %}
{{highest['price']}}
amber_peak_predicted_4h:
friendly_name: "Amber 4 hour peak predicted"
unit_of_measurement: "¢/kWh"
value_template: >-
{% set forecast = states.sensor.amber_general_usage_price.attributes['price_forcecast'] %}
{% set highest = forecast[0:8] | sort(reverse=true, attribute='price') | first() %}
{{highest['price']}}
amber_peak_predicted_12h:
friendly_name: "Amber 12 hour peak predicted"
unit_of_measurement: "¢/kWh"
value_template: >-
{% set forecast = states.sensor.amber_general_usage_price.attributes['price_forcecast'] %}
{% set highest = forecast[0:24] | sort(reverse=true, attribute='price') | first() %}
{{highest['price']}}
amber_average_predicted_2h:
friendly_name: "Amber 2 hour average predicted"
unit_of_measurement: "¢/kWh"
value_template: >-
{% set forecast = states.sensor.amber_general_usage_price.attributes['price_forcecast'] %}
{{ ((forecast[0:4] | map(attribute='price') | map('float') | sum) / 2) | round(2) }}
amber_average_predicted_4h:
friendly_name: "Amber 4 hour average predicted"
unit_of_measurement: "¢/kWh"
value_template: >-
{% set forecast = states.sensor.amber_general_usage_price.attributes['price_forcecast'] %}
{{ ((forecast[0:8] | map(attribute='price') | map('float') | sum) / 4) | round(2) }}
amber_average_predicted_12h:
friendly_name: "Amber 12 hour average predicted"
unit_of_measurement: "¢/kWh"
value_template: >-
{% set forecast = states.sensor.amber_general_usage_price.attributes['price_forcecast'] %}
{{ ((forecast[0:24] | map(attribute='price') | map('float') | sum) / 12) | round(2) }}
amber_electricity_cost_per_hour:
friendly_name: "Amber Electricity Cost Per Hour"
unit_of_measurement: '¢/hr'
icon_template: mdi:power-plug
value_template: "{{ (((states('sensor.amber_general_usage_price') | float) * (states('sensor.sum_power_consumption')) | float) / 1000) | round(2) }}"
amber_electricity_cost_predicted_2h:
friendly_name: "Amber 2h Electricity Cost Predicted"
# unit_of_measurement: '$'
icon_template: mdi:power-plug
value_template: "{{ '${:,.2f}'.format((((states('sensor.amber_average_predicted_2h') | float) * 2 * (states('sensor.sum_power_consumption')) | float) / 1000 / 100) | round(2)) }}"
amber_electricity_cost_predicted_4h:
friendly_name: "Amber 4h Electricity Cost Predicted"
# unit_of_measurement: '$'
icon_template: mdi:power-plug
value_template: "{{ '${:,.2f}'.format((((states('sensor.amber_average_predicted_4h') | float) * 4 * (states('sensor.sum_power_consumption')) | float) / 1000 / 100) | round(2)) }}"
amber_electricity_cost_predicted_12h:
friendly_name: "Amber 12h Electricity Cost Predicted"
# unit_of_measurement: '$'
icon_template: mdi:power-plug
value_template: "{{ '${:,.2f}'.format((((states('sensor.amber_average_predicted_12h') | float) * 12 * (states('sensor.sum_power_consumption')) | float) / 1000 / 100) | round(2)) }}"