Hi there community.
Exposition: I have a door sensor and a swtich for the entrance lights. For now, it works like this:
When the door sensor changes to opened, the lights turn on, when door sensor closes, lights turn off in 60s. Ok, easy.
What I would achieve: When the door sensor is opened, IF the entrance lights are already on BEFORE opening the door sensor, when that door sensor closes, the lights should turn off immediatly; but if the lights are off BEFORE opening the door sensor, when the door sensor closes, the light should remain on 60s and then turn off.
As I have no idea with templates and programming, looking there and asking GPT, I’ve come with the next code, but HA says “Message malformed: extra keys not allowed @ data[‘action’][0][‘choose’][0][‘default’]”
What’s malformed about this code?
alias: on off entrance lights
description: ""
trigger:
- platform: state
entity_id: binary_sensor.entrance_sensor_opening
to: "on"
- platform: state
entity_id: binary_sensor.entrance_sensor_opening
to: "off"
condition: []
action:
- choose:
- conditions:
- condition: template
value_template: "{{ is_state('light.entrance_light', 'on') }}"
sequence:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.last_light_state
data: {}
default:
- service: input_boolean.turn_off
target:
entity_id: input_boolean.last_light_state
- conditions:
- condition: template
value_template: >-
{{ is_state('binary_sensor.entrance_door_opening', 'off') and
is_state('input_boolean.last_light_state', 'on') }}
sequence:
- service: light.turn_off
data: {}
target:
area_id: entrance
entity_id: light.entrance_light
- conditions:
- condition: template
value_template: >-
{{ is_state('binary_sensor.entrance_door_opening', 'off') and
is_state('input_boolean.last_light_state', 'off') }}
sequence:
- delay:
hours: 0
minutes: 1
seconds: 0
milliseconds: 0
- service: light.turn_off
data: {}
target:
area_id: entrance
entity_id: light.entrance_light
mode: single
Seems that the problem is with the DEFAULT but…what should be there?
NOTE: I’ve tried deleting just the line default: then I can save, but there’s no action when opening door in any situation.
Thanks in advance