Difference between revisions of "Towel rails logic"

From Simon's Help System
Jump to navigation Jump to search
Line 1: Line 1:
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.
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 input_boolean turn_on command.  There are two boolean's per rail, one for solar and one for the scheduler.
<pre>
<pre>
alias: Heated rails on
alias: Heated rails on
Line 10: Line 10:
condition: []
condition: []
action:
action:
   - service: switch.turn_on
   - service: input_boolean.turn_on
     target:
     target:
       entity_id:
       entity_id:
         - switch.laundry_towel
         - input_boolean.master_bath_towel_solar
         - switch.master_bath
         - input_boolean.rachel_bathroom_towel_solar
         - switch.sarah_bath_towel
         - input_boolean.girls_towel_rail_solar
         - switch.girls_bath_towel
         - input_boolean.laundry_towel_solar
     data: {}
     data: {}
  - service: notify.notify
mode: single
    data:
</pre>
      message: Heated rails ON
mode: single</pre>


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''
The solar system does not turn off rails if they are scheduled ON, instead it just turns of the solar input_booleans for all rails


<pre>
<pre>
Line 35: Line 33:
condition: []
condition: []
action:
action:
   - entity_id: switch.master_bath
   - service: input_boolean.turn_off
     service: switch.turn_{{ states('input_boolean.master_bath') }}
     target:
  - entity_id: switch.girls_bath_towel
      entity_id:
    service: switch.turn_{{ states('input_boolean.girls_bath_towel') }}
        - input_boolean.master_bath_towel_solar
  - entity_id: switch.laundry_towel
        - input_boolean.rachel_bathroom_towel_solar
    service: switch.turn_{{ states('input_boolean.laundry_towel') }}
        - input_boolean.girls_towel_rail_solar
  - entity_id: switch.sarah_bath_towel
        - input_boolean.laundry_towel_solar
    service: switch.turn_{{ states('input_boolean.sarah_bath_towel') }}
     data: {}
  - service: notify.notify
     data:
      message: Heated rails OFF
mode: single
mode: single
</pre>
</pre>


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 boolean logic is applied.  Using an OR gate, if either solar or scheduler wants the rails on they are turned ON. There is separate ON and OFF logic for each towel rail:  


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.
<pre>
alias: Girls rail ON
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.girls_towel_rail
      - input_boolean.girls_towel_rail_solar
condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: input_boolean.girls_towel_rail
        state: "on"
      - condition: state
        entity_id: input_boolean.girls_towel_rail_solar
        state: "on"
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.girls_towel_rail
mode: single
</pre>


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.
and Using an AND gate, if both solar or scheduler wants the rails off they are turned OFF.


<pre>
<pre>
alias: heated_rails
alias: Girls rail OFF
description: Set Towel Rail status on change
description: ""
trigger:
trigger:
   - platform: state
   - platform: state
     entity_id:
     entity_id:
       - input_boolean.master_bath
       - input_boolean.girls_towel_rail
       - input_boolean.girls_bath_towel
       - input_boolean.girls_towel_rail_solar
       - input_boolean.laundry_towel
condition:
       - input_boolean.sarah_bath_towel
  - condition: and
condition: []
    conditions:
       - condition: state
        entity_id: input_boolean.girls_towel_rail
        state: "off"
       - condition: state
        entity_id: input_boolean.girls_towel_rail_solar
        state: "off"
action:
action:
   - service: switch.turn_{{ trigger.to_state.state }}
   - service: switch.turn_off
     data:
     data: {}
      entity_id: switch.{{ trigger.to_state.object_id }}
     target:
  - service: notify.notify
       entity_id: switch.girls_towel_rail
     data:
mode: single</pre>
       message: Heated Rails Toggled
mode: single
</pre>

Revision as of 10:50, 8 November 2023

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 input_boolean turn_on command. There are two boolean's per rail, one for solar and one for the scheduler.

alias: Heated rails on
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.grid_feed_in
    above: "800"
    for: "00:01:00"
condition: []
action:
  - service: input_boolean.turn_on
    target:
      entity_id:
        - input_boolean.master_bath_towel_solar
        - input_boolean.rachel_bathroom_towel_solar
        - input_boolean.girls_towel_rail_solar
        - input_boolean.laundry_towel_solar
    data: {}
mode: single

The solar system does not turn off rails if they are scheduled ON, instead it just turns of the solar input_booleans for all rails

alias: Heated rails OFF
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.meter_power_a
    above: "-100"
    for: "00:00:30"
condition: []
action:
  - service: input_boolean.turn_off
    target:
      entity_id:
        - input_boolean.master_bath_towel_solar
        - input_boolean.rachel_bathroom_towel_solar
        - input_boolean.girls_towel_rail_solar
        - input_boolean.laundry_towel_solar
    data: {}
mode: single

Finally boolean logic is applied. Using an OR gate, if either solar or scheduler wants the rails on they are turned ON. There is separate ON and OFF logic for each towel rail:

alias: Girls rail ON
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.girls_towel_rail
      - input_boolean.girls_towel_rail_solar
condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: input_boolean.girls_towel_rail
        state: "on"
      - condition: state
        entity_id: input_boolean.girls_towel_rail_solar
        state: "on"
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.girls_towel_rail
mode: single

and Using an AND gate, if both solar or scheduler wants the rails off they are turned OFF.

alias: Girls rail OFF
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.girls_towel_rail
      - input_boolean.girls_towel_rail_solar
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: input_boolean.girls_towel_rail
        state: "off"
      - condition: state
        entity_id: input_boolean.girls_towel_rail_solar
        state: "off"
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.girls_towel_rail
mode: single