Humidity and motion sensor

I’m trying to create an automation which turns off my lights in the bathroom after 5 minutes if there hasn’t been any motion and the humidity is below 55 %. Right now it doesn’t turn off the lights and I suspect it is because the humidity isn’t below 55 after the 5 minutes.

Any help?

alias: Stort Badeværelse lys
description: ""
triggers:
  - type: motion
    device_id: f2f65f1606bc8b2ef4bc0ec749b68f81
    entity_id: 74005ed4b477558b1606e575f4122ced
    domain: binary_sensor
    trigger: device
    id: "On"
  - type: no_motion
    device_id: f2f65f1606bc8b2ef4bc0ec749b68f81
    entity_id: 74005ed4b477558b1606e575f4122ced
    domain: binary_sensor
    trigger: device
    id: "Off"
    for:
      hours: 0
      minutes: 5
      seconds: 0
conditions: []
actions:
  - choose:
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id:
                  - "On"
              - condition: state
                entity_id: input_boolean.nat
                state: "off"
        sequence:
          - if:
              - type: is_illuminance
                condition: device
                device_id: f2f65f1606bc8b2ef4bc0ec749b68f81
                entity_id: b159a44f8fc6ddd9fca05b061af5cba3
                domain: sensor
                below: 50
            then:
              - type: turn_on
                device_id: 2bb0aa2b78a64c193a6805fc7bf4de4e
                entity_id: 4ad31d47b064bc732fdca31d12063454
                domain: light
                brightness_pct: 30
        alias: Tænd dag
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id:
                  - "On"
              - condition: state
                entity_id: input_boolean.nat
                state: "on"
        sequence:
          - type: turn_on
            device_id: 4b76c9b725a23b91f85c3ff70fa08ec9
            entity_id: 402123acfccae1ae8e5250045bc16d3b
            domain: light
            brightness_pct: 5
        alias: Tænd nat
      - conditions:
          - condition: trigger
            id:
              - "Off"
            enabled: false
          - type: is_humidity
            condition: device
            device_id: 7c04cd14f4cfb97cc51540c37617e131
            entity_id: a4adcabaf0ec5fd0b7a25a5855a7cfe3
            domain: sensor
            below: 50
            enabled: false
          - condition: and
            conditions:
              - condition: trigger
                id:
                  - "Off"
              - type: is_humidity
                condition: device
                device_id: 7c04cd14f4cfb97cc51540c37617e131
                entity_id: a4adcabaf0ec5fd0b7a25a5855a7cfe3
                domain: sensor
                below: 55
        sequence:
          - type: turn_off
            device_id: 2bb0aa2b78a64c193a6805fc7bf4de4e
            entity_id: 4ad31d47b064bc732fdca31d12063454
            domain: light
        alias: Sluk
mode: restart

Oh, how do I format the code?

Hello pmuhlig,

Thanks for coming here and asking a question.
Would you be so kind as to adjusting the format of your code so that we can read it properly & check the YAML spacing, etc. Editing your original is the preferred way. It is very hard for us to tell what is what when the text formatter jumbles everything like that.
You can use the </> button like this… How to format your code in forum posts
OR… Here is an example of how to fix it from the site FAQ Page.
How to help us help you - or How to ask a good question.

Yeah sorry, i tried formattin on mobile. I’ve changed the post now.

Without delving too deep in hour code: if both humidity and motion need to be in the right state for things to happen, then you need triggers for both motion and humidity changing to a desired state. Then in the conditions, check for both. That way you cover all the situation for which actions need to occur. You now have only half of that, meaning it does not cover all the situations.

I have too many automations with identical triggers and conditions, it would be nice to have a easier solution to say;

  • if a changes to true
  • if b changes to true
  • when both a and b are true
  • execute action

There are changes coming to the automation triggers, as I understand it will be possible to more easily set things like that.

For now, a single template trigger will act as both a trigger and condition, because the template only evaluates true when all conditions in it are met.

So is there any way to make the automation run like I want?

Oh I think I got it. I add the humidity as a trigger and have the condition be both the motion sensor trigger and the humidity?

Yes, that’s it.

Thanks. I’ll test it the next time I take a shower lol

Sadly it isn’t working. Have any idea whats wrong?

alias: Stort Badeværelse lys
description: ""
triggers:
  - type: motion
    device_id: f2f65f1606bc8b2ef4bc0ec749b68f81
    entity_id: 74005ed4b477558b1606e575f4122ced
    domain: binary_sensor
    trigger: device
    id: "On"
  - type: no_motion
    device_id: f2f65f1606bc8b2ef4bc0ec749b68f81
    entity_id: 74005ed4b477558b1606e575f4122ced
    domain: binary_sensor
    trigger: device
    id: "Off"
    for:
      hours: 0
      minutes: 5
      seconds: 0
  - type: humidity
    device_id: 7c04cd14f4cfb97cc51540c37617e131
    entity_id: a4adcabaf0ec5fd0b7a25a5855a7cfe3
    domain: sensor
    trigger: device
    below: 55
    id: Fugt
conditions: []
actions:
  - choose:
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id:
                  - "On"
              - condition: state
                entity_id: input_boolean.nat
                state: "off"
        sequence:
          - if:
              - type: is_illuminance
                condition: device
                device_id: f2f65f1606bc8b2ef4bc0ec749b68f81
                entity_id: b159a44f8fc6ddd9fca05b061af5cba3
                domain: sensor
                below: 50
            then:
              - type: turn_on
                device_id: 2bb0aa2b78a64c193a6805fc7bf4de4e
                entity_id: 4ad31d47b064bc732fdca31d12063454
                domain: light
                brightness_pct: 30
        alias: Tænd dag
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id:
                  - "On"
              - condition: state
                entity_id: input_boolean.nat
                state: "on"
        sequence:
          - type: turn_on
            device_id: 4b76c9b725a23b91f85c3ff70fa08ec9
            entity_id: 402123acfccae1ae8e5250045bc16d3b
            domain: light
            brightness_pct: 5
        alias: Tænd nat
      - conditions:
          - condition: and
            conditions:
              - condition: and
                conditions:
                  - condition: trigger
                    id:
                      - "Off"
                  - condition: trigger
                    id:
                      - Fugt
        sequence:
          - type: turn_off
            device_id: 2bb0aa2b78a64c193a6805fc7bf4de4e
            entity_id: 4ad31d47b064bc732fdca31d12063454
            domain: light
        alias: Sluk
mode: restart

Do you have automation traces? If you do not have any, the trigger wasn’t there, if you have, you’ll see what condition failed path the automation took. Combining both the start and end automation in one makes the automation complex, and device triggers and conditions are also hard to follow.

Yeah but I’m unsure how to read the traces tbh. What do I look for?

It is explained here:

You get to see a graph of all parts of the automation. Colors show what got executed and what not. Click on a node to see what happened in that node. If a condition failed you’ll see why. You’ll see why the automation chose a path to perform or skip an action.