Here is my new code (at the bottom) which works a treat but I used to have an automation that checked the power rate on HA restart and switched it if not right as sometimes I inadvertently restarted HA during peak or offpeak changeover times (0700, 1100, 1700, 2100) which screwed all my other automations up.
Question is: How to I pass peak
or offpeak
variables to my script on HA start?
- alias: Check power rates weekday on HA restart
id: 1cc048e2-0713-480a-b61b-674bb62f56e7
trigger:
- platform: homeassistant
event: start
condition:
condition: and
conditions:
- condition: state
entity_id: binary_sensor.workday_sensor
state: 'on'
- condition: state
entity_id: sensor.power_rate
state: 'offpeak'
- condition: or
conditions:
- condition: time
after: '07:00:00'
before: '11:00:00'
- condition: time
after: '17:00:00'
before: '21:00:00'
action:
- service: script.toggle_power_rates
The below code works fine. Just need to somehow add and pass the variable in the code above.
- alias: Toggle power rates weekday
id: 53d0e6be-13fc-45a8-a5a7-939cda57f3fa
trigger:
- platform: time
at: '07:00:00'
variables:
tariff: "peak"
- platform: time
at: '11:00:00'
variables:
tariff: "offpeak"
- platform: time
at: '17:00:00'
variables:
tariff: "peak"
- platform: time
at: '21:00:00'
variables:
tariff: "offpeak"
condition:
- condition: state
entity_id: binary_sensor.workday_sensor
state: 'on'
action:
- service: script.toggle_power_rates
data:
option: "{{ tariff }}"
## Modified due to service change https://www.home-assistant.io/integrations/utility_meter/ ##
script:
toggle_power_rates:
alias: Toggle Power Rates
icon: "mdi:power-sleep"
description: 'Toggle the power rates from peak to off-peak for the Utility Meter integration'
sequence:
- service: select.select_option
target:
entity_id:
- select.energy_house_d
- select.energy_house_m
- select.energy_house_yr
- select.energy_ali_office_d
- select.energy_ali_office_m
- select.energy_pool_d
- select.energy_pool_m
- select.energy_washing_machine_d
- select.energy_washing_machine_m
- select.energy_hwc_d
- select.energy_hwc_m
- select.energy_spa_d
- select.energy_spa_m
data:
option: "{{ option }}"