I have an automation that switches a light to a certain brightness level when one of my PIRs detected motion. This works fine.
alias: gang loop
description: ''
trigger:
- platform: state
entity_id: binary_sensor.gang_pir1gang_263
to: 'on'
- platform: state
entity_id: binary_sensor.gang_pir2gang_269
to: 'on'
condition: []
action:
- repeat:
until:
- condition: and
conditions:
- condition: state
entity_id: binary_sensor.gang_pir1gang_263
state: 'off'
for:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- condition: state
entity_id: binary_sensor.gang_pir2gang_269
state: 'off'
for:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
sequence:
- service: light.turn_on
target:
entity_id: light.gang_ganglamp_110
- delay:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- service: light.turn_off
target:
entity_id: light.gang_ganglamp_110
mode: single
I want to add a condition to this automation to NOT run this automation when the lamp already has a brightness >99%.
.
Reason: when I switch the light manually on (at 100%), I want to switch it also manually off, not via the automation .Sometimes I need this light on while nobody triggers the PIRs.
If I paste below code in the tempate editor while the lamp is out.
{{state_attr(âlight.gang_ganglamp_110â,âbrightnessâ) | int > 99}} â returns false
{{state_attr(âlight.gang_ganglamp_110â,âbrightnessâ) | int < 99}} â returns true
When I add this code to the automation as template, the light no longer switches on when one of the PIRs get triggered, not when I use ">"or â<â in the condition.
Iâm no coding expert but when I look at the step details it seems like the numeric state condition checks the state of the entity (on/off) while we need it to check an attribute (brightness).
I got 2x the same error on the two conditions.
result: false message: attribute âbrightnessâ of entity light.gang_ganglamp_110 does not exist
see screenshot.
My other problem is that this automation does not solve my problem.
What I want:
1: the light to switch on (dimmed) when PIR is triggered and after time-out switch off .
2: when I manually double click the light switch, the light should go to 100%. The automation should not switch off the light.
Problem:
The switch is in reach of the PIR, so the repeat-until loop will be running once the switch is pressed.
When the light is set to 100% during the loop, the light will dim after timeout and continue in the loop.
In summary I have 2 questions:
1: is it OK to get the message âattribute does not existâ?
2: how can I improve the automation to make it work as intended.
id: '1639313865361'
alias: gang loop
description: ''
trigger:
- platform: state
entity_id: binary_sensor.gang_pir1gang_263
to: 'on'
- platform: state
entity_id: binary_sensor.gang_pir2gang_269
to: 'on'
condition:
- condition: or
conditions:
- condition: numeric_state
entity_id: light.gang_ganglamp_110
attribute: brightness
below: 98
- condition: state
entity_id: light.gang_ganglamp_110
state: 'off'
action:
- repeat:
until:
- condition: and
conditions:
- condition: state
entity_id: binary_sensor.gang_pir1gang_263
state: 'off'
for:
hours: 0
minutes: 0
seconds: 5
- condition: state
entity_id: binary_sensor.gang_pir2gang_269
state: 'off'
for:
hours: 0
minutes: 0
seconds: 5
sequence:
- service: light.turn_on
target:
entity_id: light.gang_ganglamp_110
data:
brightness: 40
- delay:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- service: light.turn_off
target:
entity_id: light.gang_ganglamp_110
mode: single
Let me try to explain why Iâd like to use brightness in my automation.
In our hallway I want to switch on the light based on motion and switch off after x-time no motion.
I have an automation that switched the lights to a 40% brightness (dimmed) when one of the PIRs is triggered. After X-time no motion, the lights should switch off.
I donât want the lights to switch based on motion when I need to be in the hallway many times. For example when I put my groceries away. To override the automation I want to double click the wall switch (Fibaro Dimmer 2 with pulse sensor) which sets the brightness to 100%. In the automation I want to kill the loop when brightness is 100% and also prevent the loop to restart.
When I switch the lights off, the automation should take over again.
Looking forward to your suggestions how I can do this or what alternatives you see for this.