eteanton
(Eteanton)
June 11, 2024, 7:52pm
1
Hi, my Automation from ChatGPT can’t be saved. The Error
Message malformed: required key not provided @ data[‘action’]
Is shown. What is wrong with the code
alias: Bewegungssensor Kinderzimmer: Licht rot schalten
description: "Schaltet Licht im Kinderzimmer rot, wenn Bewegung zwischen 20:00 und 07:00 Uhr erkannt wird."
trigger:
- platform: device
device_id: binary_sensor.hue_sensor_kinderzimmer_occupancy
entity_id: binary_sensor.hue_sensor_kinderzimmer_occupancy
domain: binary_sensor
type: motion
- platform: time
after: '20:00:00'
before: '07:00:00'
condition: []
action:
- service: scene.create # Create scene "Vorher Tom" (if it exists)
data:
scene: scene.vorher_tom
- service: light.turn_on # Turn on lights red
data:
entity_id:
- light.hue_arwen
- light.hue_bunny
- light.hue_emil
- light.hue_imperator
- light.hue_sauron
color_name: red
brightness: 255
- delay: '01:00' # Wait for 1 minute
- service: scene.turn_on # Turn on scene "Vorher Tom" again
data:
entity_id: scene.vorher_tom
Don’t use chat bots. They’re terrible for HA YAML.
Replace data
with target
.
eteanton
(Eteanton)
June 11, 2024, 8:07pm
3
Thanks for your fast response. Which data should i replace? When i replace all data with target, í will get the same error
That’s not the only problem. You seem to want to restrict the automation to only occur during certain times, which you could do with a time condition , but not a time trigger . Understanding this difference is a common hurdle for new users. I would suggest reviewing the opening paragraphs of the linked documentation.
Also, scene.create isn’t going to do anything useful without snapshot_entities
being defined.
Instead of trying to fix the YAML, it would be much easier if you just started over and used the UI wizard to create this automation, especially since it’s relatively simple.
msp1974
(Mark P)
June 11, 2024, 8:31pm
5
I suspect it is the : in your alias. Yaml wont accept this unless quoted.
123
(Taras)
June 11, 2024, 9:40pm
6
alias: Bewegungssensor Kinderzimmer: Licht rot schalten
description: "Schaltet Licht im Kinderzimmer rot, wenn Bewegung zwischen 20:00 und 07:00 Uhr erkannt wird."
trigger:
- platform: state
entity_id: binary_sensor.hue_sensor_kinderzimmer_occupancy
from: 'off'
to: 'on'
condition:
- condition: time
after: '20:00:00'
before: '07:00:00'
action:
- variables:
my_lights:
- light.hue_arwen
- light.hue_bunny
- light.hue_emil
- light.hue_imperator
- light.hue_sauron
- service: scene.create
data:
scene_id: vorher_tom
snapshot_entities: "{{ my_lights }}"
- service: light.turn_on
target:
entity_id: "{{ my_lights }}"
data:
color_name: red
brightness: 255
- delay: '01:00'
- service: scene.turn_on
target:
entity_id: scene.vorher_tom
1 Like