Thanks for taking the time to explain that. I have the following sensor:
{% set n_month = now().month %}
{% set n_hour = now().hour %}
{% if now().weekday() in (5,6) and n_hour > 11 and n_hour < 14 %}
{% set tou_period = 'Free' %}
{% else %}
{% set tou_period = 'Shoulder' %}
{% set is_summer = (n_month <= 3 or n_month >= 11) %}
{% set is_winter = (6 <= n_month <= 8 ) %}
{% if n_hour >= 22 or n_hour < 7 %}
{% set tou_period = 'Offpeak' %}
{% elif ((is_summer and (14 <= n_hour <= 19))
or (is_winter and (14 <= n_hour <= 19)))
and (is_state("binary_sensor.workday_sensor", "on")) %}
{% set tou_period = 'Peak' %}
{% endif %}
{% endif %}
{{tou_period}}
I get two free hours of electricity on Saturdays amd Sundays courtesy of Red Energy’s EV Plan, hence the extra logic. I don’t have seasonal prices, but left your logic in there in case I ever do (but I changed the TOU period to be the same for summer and winter).
When I plug this into Developer Tools, it says the sensor updates every minute. That’s OK I guess, but I thought to do this (inside my templates.yaml file):
- trigger:
- platform: time_pattern
minutes: 0
# update every hour on the hour
- platform: homeassistant
event: start
sensor:
# Australian Ausgrid NSW Peak-shoulder-offpeak sensor defined
# https://www.ausgrid.com.au/Your-energy-use/Meters/Time-of-use-pricing
# Peak: 2pm - 8pm on working weekdays 1 November - 31 March;
# Peak: 5pm - 9pm on working weekdays 1 June - 31 August
# Off-peak: 10pm - 7am
# Shoulder: all other times
- name: TOU Period
icon: mdi:clock-time-three-outline
state: >
{% set n_month = now().month %}
{% set n_hour = now().hour %}
{% if now().weekday() in (5,6) and n_hour > 11 and n_hour < 14 %}
{% set tou_period = 'Free' %}
{% else %}
{% set tou_period = 'Shoulder' %}
{% set is_summer = (n_month <= 3 or n_month >= 11) %}
{% set is_winter = (6 <= n_month <= 8 ) %}
{% if n_hour >= 22 or n_hour < 7 %}
{% set tou_period = 'Offpeak' %}
{% elif ((is_summer and (14 <= n_hour <= 19))
or (is_winter and (14 <= n_hour <= 19)))
and (is_state("binary_sensor.workday_sensor", "on")) %}
{% set tou_period = 'Peak' %}
{% endif %}
{% endif %}
{{tou_period}}
- name: "Electricity Tariff"
state: >-
{% if is_state('sensor.tou_period', 'Free') %}
0
{% else %}
{% if is_state('sensor.tou_period', 'Peak') %}
.484
{% elif is_state('sensor.tou_period', 'Shoulder') %}
.33
{% else %}
.22
{% endif %}
{% endif %}
unique_id: electricity_tariff
unit_of_measurement: AUD/kWh
I think this means the TOU and tariff sensors only update on the hour, and on HA startup. Reckon this is right? I didn’t bother setting up input_numbers
for the tariff, and just coded the tariffs directly in the sensor. Do I need to do anything else in there, or is just coding the numbers directly like that sufficient (maybe with regard to it being a float or something)?
I’m not sure if you still use 3 automations to change the tariff, but I’m using a single one to update my two Utility Meters, like this:
alias: Tariff Utility Meters Update
description: ""
trigger:
- platform: state
entity_id:
- sensor.tou_period
condition: []
action:
- service: select.select_option
data:
option: "{{ states ('sensor.tou_period') }}"
target:
entity_id:
- select.daily_import
- service: select.select_option
data:
option: "{{ states ('sensor.tou_period') }}"
target:
entity_id:
- select.monthly_import
mode: single
Just a bit simpler! Thanks again for your invaluable help…