Towel rails logic

From Simon's Help System
Revision as of 10:43, 31 August 2023 by Simon (talk | contribs)
Jump to navigation Jump to search

The towel rails can be scheduled (scheduler) or turned ON and OFF by the measurement of excess solar power. During the day is the incoming solar is greater than 800 watts for 1 minute then all of the rails are turned on directly, using the switch turn_on command.

alias: Heated rails on
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.grid_feed_in
    above: "800"
    for: "00:01:00"
condition: []
action:
  - service: switch.turn_on
    target:
      entity_id:
        - switch.laundry_towel
        - switch.master_bath
        - switch.sarah_bath_towel
        - switch.girls_bath_towel
    data: {}
  - service: notify.notify
    data:
      message: Heated rails ON
mode: single

Then to make sure that the solar system does not turn off rails if they are scheduled ON, I use an dummy bit set up as an Input

alias: Heated rails OFF
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.meter_power_a
    above: "-100"
    for: "00:00:30"
condition: []
action:
  - entity_id: switch.master_bath
    service: switch.turn_{{ states('input_boolean.master_bath') }}
  - entity_id: switch.girls_bath_towel
    service: switch.turn_{{ states('input_boolean.girls_bath_towel') }}
  - entity_id: switch.laundry_towel
    service: switch.turn_{{ states('input_boolean.laundry_towel') }}
  - entity_id: switch.sarah_bath_towel
    service: switch.turn_{{ states('input_boolean.sarah_bath_towel') }}
  - service: notify.notify
    data:
      message: Heated rails OFF
mode: single

Now the code above changes the state of the switch for the towel rail to whatever the state is of the dummy input bit. The names must match exactly.

Finally another automation makes sure if the dummy input bit changes state that this changes the state of the switch, and this is a complex piece of code using the offset trigger.to_state.state as an indirect way of reading the status of the input variable.

Note in the logic below has the entity_id based on the entity that changed state, so if input_boolean.laundry_towel changed state, this would have triggered the automation and then it would change the state of switch.laundry_towel to match the state of the input boolean.

alias: heated_rails
description: Set Towel Rail status on change
trigger:
  - platform: state
    entity_id:
      - input_boolean.master_bath
      - input_boolean.girls_bath_towel
      - input_boolean.laundry_towel
      - input_boolean.sarah_bath_towel
condition: []
action:
  - service: switch.turn_{{ trigger.to_state.state }}
    data:
      entity_id: switch.{{ trigger.to_state.object_id }}
  - service: notify.notify
    data:
      message: Heated Rails Toggled
mode: single