#My first go at an automation

1 messages · Page 1 of 1 (latest)

robust kestrel
#

I'm sure this has been done a million times, but I'm trying to get my bathroom lights to come on when it senses motion, then turn off after 60 seconds, however, if the door is closed, then the lights just stay on until the door is opened at which point they will turn off after 60 seconds. I've tried this, but for some reason, nothing is happening. I can only include the actions due to message length.

actions:
  - choose:
      - conditions:
          - condition: state
            entity_id: binary_sensor.motionsensor3rdreality_motion
            state: "on"
          - condition: state
            entity_id: binary_sensor.backdoorsensor_opening
            state: "on"
        sequence:
          - target:
              entity_id: light.bathroom
            data:
              brightness_pct: 100
              color_name: white
            action: light.turn_on
          - delay: "00:01:00"
          - target:
              entity_id: light.bathroom
            action: light.turn_off
            data: {}
      - conditions:
          - condition: state
            entity_id: binary_sensor.motionsensor3rdreality_motion
            state: "on"
          - condition: state
            entity_id: binary_sensor.backdoorsensor_opening
            state: "off"
        sequence:
          - target:
              entity_id: light.bathroom
            data:
              brightness_pct: 100
              color_name: white
            action: light.turn_on
      - conditions:
          - condition: state
            entity_id: binary_sensor.motionsensor3rdreality_motion
            state: "off"
            for:
              hours: 0
              minutes: 0
              seconds: 30
          - condition: state
            entity_id: binary_sensor.backdoorsensor_opening
            state: "on"
        sequence:
          - action: light.turn_off
            metadata: {}
            data: {}
            target:
              area_id: bathroom
mode: single
open fox
#

If you could throw the whole thing on dpaste.org/ that'd be great - as it could be an issue with triggers

robust kestrel
open fox
#

So what you want is:

  1. Motion sensing: on - turn on
  2. Motion sensing: off for 60s, turn off if the door is open, else wait for the door to open and then turn off in 60s?
robust kestrel
#

basically

gloomy zodiac
#

I have mine broken into 2 automations. 1 for the door open/close that enables/disables the motion automation.

robust kestrel
#

That's an interesting way to think about it. Although I would like to make it an all in one automation.

gloomy zodiac
#

Ok. I am going to combine mine real quick. Give me a few.

open fox
#

I'd do something like this:

triggers:
  - trigger: state
    entity_id:
      - sensor.my_motion_sensor
    to: "on"
    id: turn_on
  - trigger: state
    entity_id:
      - sensor.my_motion_sensor
    to: "off"
    id: turn_off
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - turn_on
        sequence:
          - action: light.turn_on
            entity_id: light.my_bathroom_light
      - conditions:
          - condition: trigger
            id:
              - turn_off
        sequence:
          - wait_template: "{{ state('sensor.my_door_sensor') == 'on' }}"
            continue_on_timeout: true
          - delay:
              hours: 0
              minutes: 1
              seconds: 0
              milliseconds: 0
          - action: light.turn_off
            entity_id: light.my_bathroom_light
#

make it mode: restart to break it out of the wait if your motion sensor goes low for <1 minute

robust kestrel
#

Thanks @open fox I'll give this a go and get back to you

robust kestrel
#

Seeing this @open fox

open fox
#

states

#

sorry

rose cedar
#

I wrote about my bathroom light automation in another thread. #1297326787218509886 message
Personally, I don't like using delays in an automation as you can't override or easily modify the duration (aside from editing the automation.) I prefer using timer entities and trigger_ids for each part of the automation.

robust kestrel
#

@open fox sorry to bother you, this has been working brilliantly until I updated core to the latest version. Have you got any clue what's going on here? (This is in the system logs)

https://dpaste.org/q5yfa

open fox
#
Error while processing template: Template<template=({% if states(config.entity) | float < 20 %}none{% else %}flex{% endif %}) renders=2>
Error while processing template: Template<template=({% if states(config.entity) | float < 20 %}none{% else %}flex{% endif %}) renders=6>
Error while processing template: Template<template=({% if states(config.entity) | float < 20 %}none{% else %}flex{% endif %}) renders=10>
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2354, in forgiving_float_filter
return float(value)
^^^^^^^^^^^^
ValueError: could not convert string to float: 'unknown'

config.entity is returning "unknown" which can't be converted to a float cos it's not a number. I don't know where you are referencing that.. doesn't look like a sensor name

robust kestrel
#

I'm not sure either, nothing's changed 🙂

open fox
#

well... i dunno, sorry

#

poke around in helpers and try to find it?

robust kestrel
#

got it, the sensor had been renamed 🤦‍♂️

open fox
#

lol

#

was it added by an integration in core?

#

might have been updated and handled the transfer badly

robust kestrel
#

oh wait, no I was wrong

open fox
#

?

robust kestrel
#

It's been a long week, so where is config.entity coming from?

open fox
#

it's apparently in a template somewhere

#

{% if states(config.entity) | float < 20 %}none{% else %}flex{% endif %}

robust kestrel
#

where would i find templates?

open fox
#

should be in your helpers tab

robust kestrel
#

the plot thickens Looks like you don't have any helpers yet!

open fox
#

then i haven't got a clue, sorry