Nice to have a neat configuration though, and this is basically exactly the situation that templates are designed for.
but its all depending of the view of the user.
combining 2 languages to 1 piece of code doesnt make it neat for me, and for certain not when in the end you have more characters.
for me it is more neat to have 4 lines like this:
trigger: {platform: state, entity_id: binary_sensor.aken_magala, to: on}
then a block like this:
data_template:
entity_id: >
{% if is_state('binary_sensor.aken_arvuti', 'on') and is_state('binary_sensor.aken_telekas', 'on') and is_state('binary_sensor.aken_magala', 'on')%}
group.kyte_2korrus
{% elif is_state('binary_sensor.aken_arvuti', 'on') and is_state('binary_sensor.aken_telekas', 'on') %}
group.kyte_2korrus1
{% elif is_state('binary_sensor.aken_telekas', 'on') %}
climate.elutuba
{% elif is_state('binary_sensor.aken_magala', 'on') %}
climate.magala
{% endif %}
btw⌠i got it working problem was climate.turn_off
- alias: KĂTE / Kinni aken on avatud
trigger:
- platform: state
entity_id: binary_sensor.aken_arvuti
from: 'off'
to: 'on'
- platform: state
entity_id: binary_sensor.aken_telekas
from: 'off'
to: 'on'
- platform: state
entity_id: binary_sensor.aken_magala
from: 'off'
to: 'on'
action:
- service: climate.set_operation_mode
data_template:
operation_mode: "off"
entity_id: >
{% if is_state('binary_sensor.aken_arvuti', 'on') and is_state('binary_sensor.aken_telekas', 'on') and is_state('binary_sensor.aken_magala', 'on')%}
climate.elutuba, climate.magala, climate.trepp
{% elif is_state('binary_sensor.aken_arvuti', 'on') and is_state('binary_sensor.aken_telekas', 'on') %}
climate.elutuba, climate.trepp
{% elif is_state('binary_sensor.aken_telekas', 'on') %}
climate.elutuba
{% elif is_state('binary_sensor.aken_magala', 'on') %}
climate.magala
{% endif %}
Good work
I would (with my definition of neatness) reduce the triggerâŚ
- alias: KĂTE / Kinni aken on avatud
trigger:
platform: state
entity_id:
- binary_sensor.aken_arvuti
- binary_sensor.aken_telekas
- binary_sensor.aken_magala
to: 'on'
action:
service: climate.set_operation_mode
data_template:
operation_mode: "off"
entity_id: >
{% if is_state('binary_sensor.aken_arvuti', 'on') and is_state('binary_sensor.aken_telekas', 'on') and is_state('binary_sensor.aken_magala', 'on')%}
climate.elutuba, climate.magala, climate.trepp
{% elif is_state('binary_sensor.aken_arvuti', 'on') and is_state('binary_sensor.aken_telekas', 'on') %}
climate.elutuba, climate.trepp
{% elif is_state('binary_sensor.aken_telekas', 'on') %}
climate.elutuba
{% elif is_state('binary_sensor.aken_magala', 'on') %}
climate.magala
{% endif %}
thats an improvement i would chose too.
but combining 2 automations like:
if a==b then do c
if d==e then do f
to 1 automation like:
if a==b or d==e then if a==b do c elif d==e do f
isnt more neat but overcomplicating.
That hurts my brain
right, mine too
it was even hard to write it down correct, but still that is what is done with the climate situation
and that is why a lot off people struggle so much
Yeah, I think itâs because we all see the problem from a different perspective, which is probably why youâre good with python and I really really really struggle with it.
Like you saw
if a==b or d==e then if a==b do c elif d==e do f
But I saw
Do z to a, b or c if they == x
Horses for courses
in general i see a whole lot of people trying to combine things to a big problem.
and in my experience it is always the best way to splitt things up.
in science they splitt everything up to the smallest possible building bricks.
and use a few bricks together to create new bricks.
here you see people who have 10 automations and they want to create 1 from it.
just the other way around.
to built a wall you create 1 stone after another and then glue them together with cement.
if you take all the clay you need for the bricks and the cement together and trow it on 1 pile and try to build a wall from it you will never succeed.
but i am glad that @typeonegative figured it out, so its not that big of a problem that i am talking a bit phylosifical here
(still puzzles me why @typeonegative did ask my advise here, because i havent shown a lot off knowledge about this kind of things and other do)
you simply looks so smart
then i only can say: thank you
but like all other people i can only be smart if i know how to use the tools
and there are others here that use this kind of tools way better then me.
I know iâm late to the party but it looks like you are just trying to turn off what is on.
This chunk of code should work better for expansion in the future if you add more of these devices. Your current solution would be a pain to manage if you add 1 more switch/climate device. So to clarify, Itâs no better than the solutions you already have but it would be better for expansion because you just add to the sensor list and climate list.
entity_id: >
{% set sensors = [ 'binary_sensor.aken_arvuti', 'binary_sensor.aken_telekas', 'binary_sensor.aken_magala' ] %}
{% set climates = ['climate.elutuba', 'climate.trepp', 'climate.magala' ] %}
{%- for sensor in sensors if is_state(sensor, 'on') %}
{{- climates[sensors.index(sesnor)] }},
{% endfor %}
wow. thanx man!
if youâre feeling bold to try it, let me know if it works. May have to play with this line: {{- climates[sensors.index(sesnor)] }},
to get it to work.
Including spelling sensor correctly in the bracket
Haha, oops.
{{- climates[sensors.index(sensor)] }},
Hi @petro
I know this is not related to the question, but I was wondering if you can help with my query:
- service: homeassistant.turn_off
data_template:
entity_id: >
{% if is_state('switch.livingroom_candle_control', 'on') %}
switch.livingroom_candle_control
{% endif %}
- delay: '00:00:01'
- service: homeassistant.turn_off
data_template:
entity_id: >
{% if is_state('light.living_room', 'on') %}
light.living_room
{% endif %}
- delay: '00:00:01'
- service: homeassistant.turn_off
data_template:
entity_id: >
{% if is_state('switch.livingroom_hisense_control', 'on') %}
switch.livingroom_hisense_control
{% endif %}
- delay: '00:00:01'
- service: homeassistant.turn_off
data_template:
entity_id: >
{% if is_state('switch.livingroom_etisalat', 'on') %}
switch.livingroom_etisalat
{% endif %}
- delay: '00:01:10'
- service: homeassistant.turn_off
data_template:
entity_id: >
{% if is_state('switch.livingroom_ac_control', 'on') and is_state('binary_sensor.neo_coolcam_battery_powered_pir_sensor_sensor_2', 'off') %}
switch.livingroom_ac_control
{% endif %}
whats the problem?
I am trying to create something similar to what you did above, as I am planning to add more things it is becoming complicated and I want to simplify things.
Ah, You actually have to list out what you have, you cannot create a loop. Jinja always returns a string. Jinja always returns 1 value. With those 2 limitations, you cannot create a for loop to turn on/off multiple entities in a single service.