HELP bathroom automation

Why does your automation have 5 separate choose statements (each with a single conditions) instead of a single choose statement (with five conditions)?

1 Like

I just did it with the visual editor under the automation, i think i took the easy path. But it is a still in progress job, if you see how i can improve it I’ll definitely take any advice

Sure, use the example I originally posted and simply modify it.

1 Like
alias: bathroom experiment
description: ''
trigger:
  - platform: state
    entity_id: group.bathroom_motion
    id: occupancy
    from: 'off'
    to: 'on'
    for:
      hours: 0
      minutes: 0
      seconds: 0
  - platform: state
    entity_id: group.bathroom_motion
    id: no_occupancy_3
    from: 'on'
    to: 'off'
    for:
      hours: 0
      minutes: 3
      seconds: 0
  - platform: state
    entity_id: group.bathroom_motion
    id: no_occupancy_10
    from: 'on'
    to: 'off'
    for:
      hours: 0
      minutes: 10
      seconds: 0
  - platform: state
    entity_id: group.bathroom_door
    id: door_open
    from: 'off'
    to: 'on'
  - platform: state
    entity_id: binary_sensor.bathroom_hygrostat
    id: shower_on
    from: 'off'
    to: 'on'
    for:
      hours: 0
      minutes: 1
      seconds: 0
  - platform: state
    entity_id: binary_sensor.bathroom_hygrostat
    id: shower_off
    from: 'on'
    to: 'off'
    for:
      hours: 0
      minutes: 5
      seconds: 0
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: occupancy
          - condition: state
            entity_id: light.bath_light_on_off
            state: 'off'
        sequence:
          - service: light.turn_on
            data: {}
            target:
              entity_id: light.bath_light_on_off
      - conditions:
          - condition: trigger
            id: door_open
          - condition: state
            entity_id: light.bath_light_on_off
            state: 'off'
        sequence:
          - service: light.turn_on
            data: {}
            target:
              entity_id: light.bath_light_on_off
      - conditions:
          - condition: trigger
            id: no_occupancy_3
          - condition: state
            entity_id: light.bath_light_on_off
            state: 'on'
          - condition: state
            entity_id: group.bathroom_door
            state: 'on'
        sequence:
          - service: light.turn_off
            data: {}
            target:
              entity_id: light.bath_light_on_off
      - conditions:
          - condition: trigger
            id: no_occupancy_10
          - condition: state
            entity_id: light.bath_light_on_off
            state: 'on'
          - condition: state
            entity_id: group.bathroom_door
            state: 'off'
        sequence:
          - service: light.turn_off
            data: {}
            target:
              entity_id: light.bath_light_on_off
      - conditions:
          - condition: trigger
            id: shower_on
          - condition: state
            entity_id: group.bathroom_door
            state: 'off'
          - condition: state
            entity_id: light.bath_light_on_off
            state: 'on'
        sequence:
          - service: switch.turn_on
            data: {}
            target:
              entity_id: switch.tz3000_ji4araar_ts0011_4c755449_on_off
      - conditions:
          - condition: trigger
            id: shower_off
          - condition: state
            entity_id: switch.tz3000_ji4araar_ts0011_4c755449_on_off
            state: 'on'
        sequence:
          - service: switch.turn_off
            data: {}
            target:
              entity_id: switch.tz3000_ji4araar_ts0011_4c755449_on_off
    default: []
mode: single


ok following your advice, I have this now

Not sure why you discarded the example’s use of variables and converted all of the shorthand Template Conditions into longer State Conditions. All you needed to do was copy-paste the example and then change the entity names (a 1 minute operation).

I tried with the variable but this shows up “Message malformed: expected a dictionary for dictionary value @ data[‘action’][0][‘variables’]”

Based on the the appearance of the unformatted YAML you posted initially, I believe that error message was due to incorrect indenting. The three variables under variables: should be indented; your example shows all three are vertically aligned with variables: and that’s invalid.

1 Like
alias: bathroom experiment 2
description: ''
trigger:
  - platform: state
    entity_id: group.bathroom_motion
    id: occupancy
    from: 'off'
    to: 'on'
  - platform: state
    entity_id: group.bathroom_motion
    id: no_occupancy_3
    from: 'on'
    to: 'off'
    for: '00:03:00'
  - platform: state
    entity_id: group.bathroom_motion
    id: no_occupancy_10
    from: 'on'
    to: 'off'
    for: '00:10:00'
  - platform: state
    entity_id: group.bathroom_door
    id: door_open
    from: 'off'
    to: 'on'
  - platform: state
    entity_id: binary_sensor.bathroom_hygrostat
    id: shower_on
    from: 'off'
    to: 'on'
    for: '00:01:00'
  - platform: state
    entity_id: binary_sensor.bathroom_hygrostat
    id: shower_off
    from: 'on'
    to: 'off'
    for: '00:03:30'
condition: []
action:
  - variables:
      light: light.bath_light_on_off
      fan: switch.tz3000_ji4araar_ts0011_4c755449_on_off
      door: group.bathroom_door
  - choose:
      - conditions:
          - '{{ trigger.id == ''occupancy''}}'
          - '{{ is_state(light, ''off'') }}'
        sequence:
          - service: light.turn_on
            target:
              entity_id: '{{ light }}'
      - conditions:
          - '{{ trigger.id == ''door_open''}}'
          - '{{ is_statte(light, ''off'') }}'
        sequence:
          - service: light.turn_on
            target:
              entity_id: '{{ light }}'
      - conditions:
          - '{{ trigger.id == ''no_occupancy_3''}}'
          - '{{ is_state(light, ''on'') }}'
          - '{{ is_state(door, ''on'') }}'
        sequence:
          - service: light.turn_off
            target:
              entity_id: '{{ light }}'
      - conditions:
          - '{{ trigger.id == ''no_occupancy_10''}}'
          - '{{ is_state(light, ''on'') }}'
          - '{{ is_state(door, ''off'') }}'
        sequence:
          - service: light.turn_off
            target:
              entity_id: '{{ light }}'
      - conditions:
          - '{{ trigger.id == ''shower_on''}}'
          - '{{ is_state(door, ''off'') }}'
          - '{{ is_state(light, ''on'') }}'
        sequence:
          - service: switch.turn_on
            target:
              entity_id: '{{ fan }}'
      - conditions:     
          - '{{ trigger.id == ''shower_off''}}'
          - '{{ is_state(fan, ''on'') }}'
        sequence:
          - service: switch.turn_off
            target:
              entity_id: '{{ fan }}'
    default: []
mode: single


you were totally right, it was incorrect indenting, but I think I got it right this time

For future reference, when someone gives you an automation that solves your problem, or meets the requirements of your request, that’s the post that represents the Solution. Only one post in the entire thread can represent the Solution. In this case, you took the example I posted, changed the entity names, then marked your own post as the Solution. For more information, refer to guideline 21 in the FAQ.

Im sorry i did not know that but I fixed alredy

1 Like