Configuration logic with light, motion and button

Hello all,

I got a motion sensor and a fibaro dimmer behind my wall light switch.
All work fine, using the examples I created an automation that when someone enters the kitchen, the lights turn on, stay on while motion is being detected and slowly turn off when nobody is in the kitchen for 1 minute.

How can I solve the next problem:

I walk in the kitchen, the lights turn on. I push the button to toggle the lights off and on again, and want them to stay on even after the 1 minute when nobody is in the kitchen.

The motion sensor constantly kicks off the script to turn off the lights after a delay of 1 minute…

Anyone stumbled accross the same problem?

1 Like

What is the “button” to toggle the lights off and on again? You could configure a input_boolean which is not shown on the frontend and bind a condition to it so the light only get’s turned off if this input is false. And put it true whenever you turn on the light manually.

Cheers

Thanks for the reply PhyberApex,

The “button” is the wall switch to control the light. It has a spring so that is always returns to its initial position. Behind the switch is a fibaro dimmer 2 installed. When HA is not running or errord, people can still use the button to control the light. (1push = on/off remembering brightness, 2 pushes is on at full brightness)

If I configure such input_boolean how can I flip the value of it? Do I need an other button next to my wall switch?

Okay to help you out here I would need a bit more information. I am not familiar with fibaro. So the switch works regardless of HA but can it send something to HA or can HA fetch the light status?

HA can receive a state change for the light, on/off.

Let me explain the problem more in depth if that helps:

There are two components:

I want to achieve three things:

  • When someone walks in the room, turn on the light, and when there is no motion detected for 1 minute, turn off the light. This automation works
  • When someone walks in the room (lights turn on), and then presses the switch, the lights go off, and as long that there is motion in the room, the lights stay off.
  • When someone walks in the room (lights turn on(, and hen presses the switch to turn off the light and within 5 seconds or so presses the switch again it turns back on the light, but then the lights should stay on forever

I tried the option provided with the input_boolean, when the sensor picks up motion it turns on the lights and sets the input_boolean.lights_on_by_motion to “on”.

I want the script that turns of the lights after a delay, to check if input_boolean.lights_on_by_motion is " on",

At every other state change from the light I clear input_boolean.lights_on_by_motion back to “off”, so that the automatic turning off fort the lightning can be ignored

The problem is then in the script thats turns off the lights, after a delay of 1 minute. I cant check the value of the input_boolean because I cant use conditions in a script sequence…

example code below:

The automation that kicks off the script to turn on the light:

alias: Keukenlamp aan bij beweging en zet deze na 1 minuut weer uit
trigger:
  - platform: state
    entity_id: sensor.fibaro_system_fgms001_motion_sensor_burglar_4
    state: "8"
action:
  service: homeassistant.turn_on
  entity_id: script.keukenlamp_aan_voor_10_minuten

The script that turns on the light and sets the input_boolean value:

sequence:
- service: script.turn_off
  data:
    entity_id: script.keukenlamp_uit_na_delay
- service: light.turn_on
  data:
    entity_id: light.fibaro_system_fgd212_dimmer_2_level_2
- service: homeassistant.turn_on
  data:
    entity_id: input_boolean.licht_keuken_aan_door_beweging
- service: script.turn_on
  data:
    entity_id: script.keukenlamp_uit_na_delay

The script that turns off the light: (called by previous script)

sequence:
- delay:
    minutes: 1
- service: light.turn_off
  data:
    entity_id: light.fibaro_system_fgd212_dimmer_2_level_2
    transition: 8
- service: homeassistant.turn_off
  data:
    entity_id: input_boolean.licht_keuken_aan_door_beweging

The problem is that in the last script here above I want to check the condition of the input_boolean, AFTER the delay. so that if the light was turned on by motion it is ’ ok’ to auto turn off, with every other state change of the light in the meantime I can reset the input_boolean so that the light wont get turned off automaticaly…

But how to do conditions in a script sequence? looks like it is not possible… I get the following error when I try:

Invalid config for [script]: [condition] is an invalid option for [script]

Is what I want even possible? Or am I trying to tackle the problem in the wrong way?

Any help welcome!

Hey,

I am actually happy that you understood what I was trying to tell you even tho I couldn’t understand it myself after reading. But what you described is exactly what I had in mind.

Could you also paste your config that is not working for you? Because conditions in scripts should work just fine. I have one like this for example:

sequence:
  - condition: template
    value_template: >-
      {{ message['pokemon_id'] in [151] }}
  - condition: template
    value_template: >-
      {{ states("input_select.pokemongo_notify") in ["Janis", "Both"] }}
  - service: notify.janis_handy_telegram
    data_template:
      title: ""
      message: >-
        MESSAGE
  - condition: template
    value_template: >-
      {{ states("input_select.pokemongo_notify") in ["Lena", "Both"] }}
  - service: notify.lena_handy_telegram
    data_template:
      title: "[Info][PokemonGo] - "
      message: >-
        MESSAGE

As you can see I have one entry condition and then another condition. Then a action and then another condition and a another action if this condition is met. This works fine. The script just cancels as soon as it gets to a condition which renders false.

Cheers

1 Like

Ah ha! That’s the way to implement a condition in a script sequence! I thank you! :slight_smile: will implement it somewhere in the comming week!

THANKS!

1 Like

Can you post your script here?