I have been. workin in base to your suggestion but I got errors can you check what im doing wrong @123Taras
alias: bathroom experiment 1
id: example_1
mode: single
max_exceeded: silent
trigger:
-
id: ‘occupancy’
platform: state
entity_id: group.bathroom_motion
from: ‘off’
to: ‘on’ -
id: ‘door_open’
platform: state
entity_id: group.bathroom_door
from: ‘off’
to: ‘on’ -
id: ‘no_occupancy_3’
platform: state
entity_id: group.bathroom_motion
from: ‘on’
to: ‘off’
for: ‘00:03:00’ -
id: ‘no_occupancy_10’
platform: state
entity_id: group.bathroom_motion
from: ‘on’
to: ‘off’
for: ‘00:10:00’ -
id: ‘lights_on_3’
platform: state
entity_id: light.bath_light on_off
from: ‘off’
to: ‘on’
for: ‘00:03:00’ -
id: ‘showerOn’
platform: state
entity_id: binary_sensor.bathroom_hygrostat
from: ‘off’
to: ‘on’
for: ‘00:01:00’ -
id: ‘showerOff’
platform: state
entity_id: binary_sensor.bathroom_hygrostat
from: ‘on’
to: ‘off’
for: ‘00:05:00’
condition: []
action:
-
variables:
light: ‘light.bath_light on_off’
fan: ‘switch.tz3000_ji4araar_ts0011_4c755449_on_off’
door: ‘group.bathroom_door’ -
choose:
-
conditions:
- “{{ trigger.id == ‘occupancy’}}”
- “{{ is_state(light, ‘off’) }}”
sequence: - service: light.turn_on
target:
entity_id: ‘{{ light }}’
-
conditions:
- “{{ trigger.id == ‘door_open’}}”
- “{{ is_state(light, ‘off’) }}”
sequence: - service: light.turn_on
target:
entity_id: ‘{{ light }}’
-
conditions:
- “{{ trigger.id == ‘no_occupancy_3’}}”
- “{{ is_state(light, ‘on’) }}”
- “{{ is_state(door, ‘on’) }}”
sequence: - service: light.turn_off
target:
entity_id: ‘{{ light }}’
-
conditions:
- “{{ trigger.id == ‘no_occupancy_10’}}”
- “{{ is_state(door, ‘off’) }}”
sequence: - service: homeassistant.turn_off
target:
entity_id:- ‘{{ light }}’
- ‘{{ fan }}’
-
conditions:
- “{{ trigger.id == ‘‘showerOn’’}}”
- “{{ is_state(door, ‘off’) }}”
sequence: - service: switch.turn_on
target:
entity_id: ‘{{ fan }}’
-
conditions:
- “{{ trigger.id == ‘‘showerOff’’}}”
sequence: - service: switch.turn_off
target:
entity_id: ‘{{ fan }}’
- “{{ trigger.id == ‘‘showerOff’’}}”
-
this is the error Message malformed: invalid template (TemplateSyntaxError: expected token ‘end of print statement’, got ‘showerOn’) for dictionary value @ data[‘action’][1][‘choose’][4][‘conditions’][0][‘value_template’
check the quotation marks here in these two templates:
conditions:
“{{ trigger.id == ‘‘showerOn’’}}”
“{{ is_state(door, ‘off’) }}”
sequence:
service: switch.turn_on
target:
entity_id: ‘{{ fan }}’
conditions:
“{{ trigger.id == ‘‘showerOff’’}}”
sequence:
service: switch.turn_off
target:
entity_id: ‘{{ fan }}’
should be:
conditions:
"{{ trigger.id == 'showerOn'}}"
"{{ is_state(door, ‘off’) }}"
sequence:
service: switch.turn_on
target:
entity_id: '{{ fan }}'
conditions:
"{{ trigger.id == 'showerOff'}}"
sequence:
service: switch.turn_off
target:
entity_id: '{{ fan }}'
also you should edit your post to correctly show the code formatting (``` both before and after the code).
alias: bathroom experiment
description: ''
trigger:
- platform: state
entity_id: group.bathroom_motion
id: occupancy
from: 'off'
to: 'on'
for:
hours: 0
minutes: 0
seconds: 0
- platform: state
entity_id: group.bathroom_motion
id: no_occupancy_3
from: 'on'
to: 'off'
for:
hours: 0
minutes: 3
seconds: 0
- platform: state
entity_id: group.bathroom_motion
id: no_occupancy_10
from: 'on'
to: 'off'
for:
hours: 0
minutes: 10
seconds: 0
- platform: state
entity_id: group.bathroom_door
id: door_open
from: 'off'
to: 'on'
- platform: state
entity_id: binary_sensor.bathroom_hygrostat
id: shower_on
from: 'off'
to: 'on'
for:
hours: 0
minutes: 1
seconds: 0
- platform: state
entity_id: binary_sensor.bathroom_hygrostat
id: shower_off
from: 'on'
to: 'off'
for:
hours: 0
minutes: 5
seconds: 0
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: occupancy
- condition: device
type: is_off
device_id: 994c822d18ff7259d7ed441c8731a423
entity_id: light.bath_light_on_off
domain: light
sequence:
- type: turn_on
device_id: 994c822d18ff7259d7ed441c8731a423
entity_id: light.bath_light_on_off
domain: light
default: []
- choose:
- conditions:
- condition: trigger
id: door_open
- condition: device
type: is_off
device_id: 994c822d18ff7259d7ed441c8731a423
entity_id: light.bath_light_on_off
domain: light
sequence:
- type: turn_on
device_id: 994c822d18ff7259d7ed441c8731a423
entity_id: light.bath_light_on_off
domain: light
default: []
- choose:
- conditions:
- condition: trigger
id: no_occupancy_3
- condition: device
type: is_on
device_id: 994c822d18ff7259d7ed441c8731a423
entity_id: light.bath_light_on_off
domain: light
- condition: state
entity_id: group.bathroom_door
state: 'on'
sequence:
- type: turn_off
device_id: 994c822d18ff7259d7ed441c8731a423
entity_id: light.bath_light_on_off
domain: light
default: []
- choose:
- conditions:
- condition: trigger
id: no_occupancy_10
- condition: device
type: is_on
device_id: 994c822d18ff7259d7ed441c8731a423
entity_id: light.bath_light_on_off
domain: light
- condition: state
entity_id: group.bathroom_door
state: 'off'
sequence:
- type: turn_off
device_id: 994c822d18ff7259d7ed441c8731a423
entity_id: light.bath_light_on_off
domain: light
default: []
- choose:
- conditions:
- condition: trigger
id: shower_on
- condition: state
entity_id: group.bathroom_door
state: 'off'
sequence:
- type: turn_on
device_id: 7577c411d5214086832ca0f51eee94e2
entity_id: switch.tz3000_ji4araar_ts0011_4c755449_on_off
domain: switch
default: []
- choose:
- conditions:
- condition: trigger
id: shower_off
- condition: device
type: is_on
device_id: 7577c411d5214086832ca0f51eee94e2
entity_id: switch.tz3000_ji4araar_ts0011_4c755449_on_off
domain: switch
sequence:
- type: turn_off
device_id: 7577c411d5214086832ca0f51eee94e2
entity_id: switch.tz3000_ji4araar_ts0011_4c755449_on_off
domain: switch
default: []
mode: single
I think I fix it. now I just have to tailored it more. this is what I came up so far
Tip
Avoid using Device Actions (and Device Conditions and Device Triggers). They don’t support templates and they’re easily twice as verbose as State Conditions, Template Conditions, Service calls, etc.
Compare how long-winded your automation has become compared to the original example (without any significant additional functionality).
I will look into this but so far is working
Why does your automation have 5 separate choose
statements (each with a single conditions
) instead of a single choose
statement (with five conditions
)?
I just did it with the visual editor under the automation, i think i took the easy path. But it is a still in progress job, if you see how i can improve it I’ll definitely take any advice
Sure, use the example I originally posted and simply modify it.
alias: bathroom experiment
description: ''
trigger:
- platform: state
entity_id: group.bathroom_motion
id: occupancy
from: 'off'
to: 'on'
for:
hours: 0
minutes: 0
seconds: 0
- platform: state
entity_id: group.bathroom_motion
id: no_occupancy_3
from: 'on'
to: 'off'
for:
hours: 0
minutes: 3
seconds: 0
- platform: state
entity_id: group.bathroom_motion
id: no_occupancy_10
from: 'on'
to: 'off'
for:
hours: 0
minutes: 10
seconds: 0
- platform: state
entity_id: group.bathroom_door
id: door_open
from: 'off'
to: 'on'
- platform: state
entity_id: binary_sensor.bathroom_hygrostat
id: shower_on
from: 'off'
to: 'on'
for:
hours: 0
minutes: 1
seconds: 0
- platform: state
entity_id: binary_sensor.bathroom_hygrostat
id: shower_off
from: 'on'
to: 'off'
for:
hours: 0
minutes: 5
seconds: 0
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: occupancy
- condition: state
entity_id: light.bath_light_on_off
state: 'off'
sequence:
- service: light.turn_on
data: {}
target:
entity_id: light.bath_light_on_off
- conditions:
- condition: trigger
id: door_open
- condition: state
entity_id: light.bath_light_on_off
state: 'off'
sequence:
- service: light.turn_on
data: {}
target:
entity_id: light.bath_light_on_off
- conditions:
- condition: trigger
id: no_occupancy_3
- condition: state
entity_id: light.bath_light_on_off
state: 'on'
- condition: state
entity_id: group.bathroom_door
state: 'on'
sequence:
- service: light.turn_off
data: {}
target:
entity_id: light.bath_light_on_off
- conditions:
- condition: trigger
id: no_occupancy_10
- condition: state
entity_id: light.bath_light_on_off
state: 'on'
- condition: state
entity_id: group.bathroom_door
state: 'off'
sequence:
- service: light.turn_off
data: {}
target:
entity_id: light.bath_light_on_off
- conditions:
- condition: trigger
id: shower_on
- condition: state
entity_id: group.bathroom_door
state: 'off'
- condition: state
entity_id: light.bath_light_on_off
state: 'on'
sequence:
- service: switch.turn_on
data: {}
target:
entity_id: switch.tz3000_ji4araar_ts0011_4c755449_on_off
- conditions:
- condition: trigger
id: shower_off
- condition: state
entity_id: switch.tz3000_ji4araar_ts0011_4c755449_on_off
state: 'on'
sequence:
- service: switch.turn_off
data: {}
target:
entity_id: switch.tz3000_ji4araar_ts0011_4c755449_on_off
default: []
mode: single
ok following your advice, I have this now
Not sure why you discarded the example’s use of variables
and converted all of the shorthand Template Conditions into longer State Conditions. All you needed to do was copy-paste the example and then change the entity names (a 1 minute operation).
I tried with the variable but this shows up “Message malformed: expected a dictionary for dictionary value @ data[‘action’][0][‘variables’]”
Based on the the appearance of the unformatted YAML you posted initially, I believe that error message was due to incorrect indenting. The three variables under variables:
should be indented; your example shows all three are vertically aligned with variables:
and that’s invalid.
alias: bathroom experiment 2
description: ''
trigger:
- platform: state
entity_id: group.bathroom_motion
id: occupancy
from: 'off'
to: 'on'
- platform: state
entity_id: group.bathroom_motion
id: no_occupancy_3
from: 'on'
to: 'off'
for: '00:03:00'
- platform: state
entity_id: group.bathroom_motion
id: no_occupancy_10
from: 'on'
to: 'off'
for: '00:10:00'
- platform: state
entity_id: group.bathroom_door
id: door_open
from: 'off'
to: 'on'
- platform: state
entity_id: binary_sensor.bathroom_hygrostat
id: shower_on
from: 'off'
to: 'on'
for: '00:01:00'
- platform: state
entity_id: binary_sensor.bathroom_hygrostat
id: shower_off
from: 'on'
to: 'off'
for: '00:03:30'
condition: []
action:
- variables:
light: light.bath_light_on_off
fan: switch.tz3000_ji4araar_ts0011_4c755449_on_off
door: group.bathroom_door
- choose:
- conditions:
- '{{ trigger.id == ''occupancy''}}'
- '{{ is_state(light, ''off'') }}'
sequence:
- service: light.turn_on
target:
entity_id: '{{ light }}'
- conditions:
- '{{ trigger.id == ''door_open''}}'
- '{{ is_statte(light, ''off'') }}'
sequence:
- service: light.turn_on
target:
entity_id: '{{ light }}'
- conditions:
- '{{ trigger.id == ''no_occupancy_3''}}'
- '{{ is_state(light, ''on'') }}'
- '{{ is_state(door, ''on'') }}'
sequence:
- service: light.turn_off
target:
entity_id: '{{ light }}'
- conditions:
- '{{ trigger.id == ''no_occupancy_10''}}'
- '{{ is_state(light, ''on'') }}'
- '{{ is_state(door, ''off'') }}'
sequence:
- service: light.turn_off
target:
entity_id: '{{ light }}'
- conditions:
- '{{ trigger.id == ''shower_on''}}'
- '{{ is_state(door, ''off'') }}'
- '{{ is_state(light, ''on'') }}'
sequence:
- service: switch.turn_on
target:
entity_id: '{{ fan }}'
- conditions:
- '{{ trigger.id == ''shower_off''}}'
- '{{ is_state(fan, ''on'') }}'
sequence:
- service: switch.turn_off
target:
entity_id: '{{ fan }}'
default: []
mode: single
you were totally right, it was incorrect indenting, but I think I got it right this time
For future reference, when someone gives you an automation that solves your problem, or meets the requirements of your request, that’s the post that represents the Solution. Only one post in the entire thread can represent the Solution. In this case, you took the example I posted, changed the entity names, then marked your own post as the Solution. For more information, refer to guideline 21 in the FAQ.
Im sorry i did not know that but I fixed alredy