Conditions in inside action

I have the following automation which turns down heat to 14C in weekdays at 10PM and is supposed to wait untill midnight on weekends (for me that means Friday and Saturday nights). I can’t get it to work on Fridays because I use the workday sensor and Friday is a work day. Any help ?

alias: Heating nights
description: ''
trigger:
  - platform: time
    at: '22:00:00'
condition:
  - condition: template
    value_template: ' {{ is_state(''input_boolean.vacation_mode'', ''off'') }}'
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: binary_sensor.workday_sensor
            state: 'off'
          - condition: or
            conditions:
              - condition: time
                weekday:
                  - fri
        sequence:
          - wait_for_trigger:
              - platform: time
                at: '23:59:00'
    default: []
  - service: climate.turn_on
    target:
      entity_id: climate.t6_pro_z_wave_programmable_thermostat
  - service: climate.set_temperature
    data:
      temperature: 14
      hvac_mode: heat
    target:
      entity_id: climate.t6_pro_z_wave_programmable_thermostat
mode: single

Suggestion:

  • Trigger on both 22:00 and 23:59 with trigger id
  • In the automation condition, match the triggered id with the day of week
  • The action part will only have the actual climate stuff

Can you explain more, maybe with code?

The condition will be true if both vacation mode and weekday are off or its a Friday. This is not what what am looking for
The whole automation should not run off vacation mode is on. If it is off then run the action if it is any weekday except on Fridays

Am intentionally not using weekday because I want the weekends and holidays. This is why am using workday sensor

## Comment: 0=Monday, 7=Sunday
        - >-
          {{ now().strftime('%H:%M') == '22:00' and ( now().weekday() == 7 or
          now().weekday() == 0 or now().weekday() == 1 or now().weekday() == 2
          or now().weekday() == 3 or now().weekday() == 4) }}
        - >-
          {{ now().strftime(''%H:%M'') == '00:00' and ( now().weekday() == 6) or
          now().weekday() == 7 }}

This will work as I don’t want to set the temperature to 14 if vacation mode is ON, like this

  • IF Input Boolean Vacation Mode is OFF (is NOT vacation)
    • Switch Heater to ON and set temperature to 14°C
    • From Sunday to Thursday Nights at 10 PM ( what if Monday is a holiday ?)
    • Friday and Saturday Nights at 00 AM
      but EITHER days/times ONLY IF
    • Binary Workday Sensor is in state OFF (is NOT public holidays)
      ELSE
  • Do Nothing

Can this code be changed to (even though it won’t fight my use case)

## Comment: 0=Monday, 7=Sunday
        - >-
          {{ now().strftime('%H:%M') == '22:00' and ( now().weekday() == 7 or
          now().weekday() == 0 or now().weekday() > 0 or now().weekday() < 5
           }}
        - >-
          {{ now().strftime(''%H:%M'') == '00:00' and ( now().weekday() == 6) or
          now().weekday() == 7 }}

Note that you can use an offset in workday, e.g.

- platform: workday
  name: Workday_Today
  country: US
  province: PA
  add_holidays:
    - "2021-11-25"
    - "2021-11-26"
    - "2021-12-23"
    - "2021-12-24"
    - "2021-12-25"
    - "2021-12-31"    
- platform: workday
  name: Workday_Tomorrow
  days_offset: 1
  country: US
  province: PA
  add_holidays:
    - "2021-11-25"
    - "2021-11-26"
    - "2021-12-23"
    - "2021-12-24"
    - "2021-12-25"
    - "2021-12-31"    

So you could also do

alias: Heating nights
description: ''
trigger:
  - platform: time
    at: '22:00:00'
    id: "trig_22"
  - platform: time
    at: '00:00:00'
    id: "trig_midnight"
condition:
  condition: or
  conditions:
    - condition: and
      conditions:
        - condition: trigger
          id: trig_22
        - condition: state
          entity_id: binary_sensor.workday_tomorrow
          state: "on"
    - condition: and
      conditions:
        - condition: trigger
          id: trig_midnight
        - condition: state
          entity_id: binary_sensor.workday_today  # midnight is already "today"
          state: "off"
action:
  - service: climate.turn_on
    target:
    entity_id: climate.t6_pro_z_wave_programmable_thermostat
  - service: climate.set_temperature
    data:
      temperature: 14
      hvac_mode: heat
    target:
    entity_id: climate.t6_pro_z_wave_programmable_thermostat
mode: single
1 Like

I don’t see vacation_mode used

This is what I get when I try to paste that code
Message malformed: Expected a dictionary @ data[‘condition’][0][‘conditions’][2][‘conditions’][1]

alias: Heating nights
description: ''
trigger:
  - platform: time
    at: '22:00:00'
  - platform: time
    at: '00:00:00'
condition:
  condition: and
  conditions:
    - condition: template
      value_template: ' {{ is_state(''input_boolean.vacation_mode'', ''off'') }}'
    - condition: state
      entity_id: binary_sensor.workday_sensor
      state: 'off'
    - condition: or
      conditions:
      ## Comment: 0=Monday, 7=Sunday
        - >-
          {{ now().strftime('%H:%M') == '22:00' and ( now().weekday() == 6 or
          now().weekday() == 0 or now().weekday() == 1 or now().weekday() == 2
          or now().weekday() == 3) }}
        - >-
          {{ now().strftime(''%H:%M'') == '00:00' and ( now().weekday() == 4) or
          now().weekday() == 5 }}
action:
  - service: climate.turn_on
    target:
    entity_id: climate.t6_pro_z_wave_programmable_thermostat
  - service: climate.set_temperature
    data:
      temperature: 14
      hvac_mode: heat
    target:
    entity_id: climate.t6_pro_z_wave_programmable_thermostat
mode: single











Received another error saving it. Fixed it to this



alias: Heating nights
description: ''
trigger:
  - platform: time
    at: '22:00:00'
  - platform: time
    at: '00:00:00'
condition:
  condition: and
  conditions:
    - condition: template
      value_template: "{{ is_state('input_boolean.vacation_mode', 'off') }}"
    - condition: state
      entity_id: binary_sensor.workday_sensor
      state: 'off'
    - condition: or
      conditions:
      ## Comment: 0=Monday, 6=Sunday
        - >-
          {{ now().strftime('%H:%M') == '22:00' and ( now().weekday() == 6 or
          now().weekday() == 0 or now().weekday() == 1 or now().weekday() == 2
          or now().weekday() == 3) }}
        - >-
          {{ now().strftime('%H:%M') == '00:00' and ( now().weekday() == 4) or
          now().weekday() == 5 }}
action:
  - service: climate.turn_on
    target:
      entity_id: climate.t6_pro_z_wave_programmable_thermostat
  - service: climate.set_temperature
    data:
      temperature: 14
      hvac_mode: heat
    target:
      entity_id: climate.t6_pro_z_wave_programmable_thermostat
mode: single

Will report later

Well, add it if you need.
You can add holidays to the workday integration, as you know, so you shouldn’t need it unless you have “impromptu” vacations…

This worked on Sunday night but failed on Monday night

This screenshot is the trace from the automation, there is nothing below that part and I am not sure I understand it.
Workday is on as today is a workday and according to the logic I put in thy OP, the heating should be set to 14C.

Only for Friday and Saturday

Friday and Saturday Nights at 00 AM
but EITHER days/times ONLY IF
Binary Workday Sensor is in state OFF (is NOT public holidays)
ELSE
Do Nothing