Hi. Thank you for your answer.
I works perfekt. Thank you.
I want 3 different positions so I did it like this.
Is it possible to put a condition (state dondition from door switch) in here only allow 100 position, not 50 or 0 if door i open?
data_template:
position: >
{% if trigger.event.data.event|int == 1002 %}
100
#is it possible to put a condition here? A state condition för a doorswitch? Only allow 100 but not 50 or 0.
{% elif trigger.event.data.event|int == 1004 %}
50
{% elif trigger.event.data.event|int == 1005 %}
0
{% endif %}
Not sure what you’re using to sense if the door is open or not. But assuming it’s a binary_sensor, then a state of ‘on’ typically means open. If you’re using something else, then adjust accordingly.
But looking at the template in your action, you really should not use an if statement without an else. If the event ever somehow wasn’t one of the ones you were expecting, this wouldn’t work and it would cause an error. You should just simply replace your last elif with an else. There’s really no reason for the last one to be an elif, and there’s really a good reason for it not to be.
Also, you could do something like this instead:
data_template:
position: >
{% set positions = {1002: 100, 1004: 50, 1005: 0} %}
{% set event = trigger.event.data.event|int %}
{% if event in positions %}
{{ positions[event] }}
{% else %}
100
{% endif %}
What error? My guess would be you don’t have an entity named binary_sensor.my_door. That was just a placeholder I put in because you didn’t say what that entity was.
Sorry. My bad.
I created a “package” for this. But when testing i moved the automation to automation.yaml because it is easier to reload automations when testing. The error was because i missed to # before some lines in my package-file.
Now i got what i want.
Is this ok for the else-part you mentioned?
No, that won’t work. You can’t call the cover.set_cover_position service with a position value of None. If binary_sensor.altandorr_sovrum is ‘on’, you either need to skip calling the service in the first place, or you need to call it with some particular value (e.g., 100.) I showed you both ways. Is there some reason you don’t think they’ll work or do what you want?
Hi. Been away for some time.
I understand I can’t use position value of none, but how to use conditions?
I only want one automation for this. Can I use condition for the “else”?
This automation works as I want but I understand it is wrong.
- alias: Knapp för markis sovrum
trigger:
- platform: event
event_type: deconz_event
event_data:
id: lumisensor_switch_6
event: 1002
- platform: event
event_type: deconz_event
event_data:
id: lumisensor_switch_6
event: 1004
- platform: event
event_type: deconz_event
event_data:
id: lumisensor_switch_6
event: 1005
action:
service: cover.set_cover_position
entity_id: cover.markis_sovrum_level
data_template:
position: >
{% if trigger.event.data.event|int == 1002 %} # This, I always want to allow
100
{% elif trigger.event.data.event|int == 1004 and
is_state('binary_sensor.altandorr_sovrum', 'off') %} # This, only if door is closed
30
{% elif trigger.event.data.event|int == 1005 and
is_state('binary_sensor.altandorr_sovrum', 'off') %} # This, only if door is closed
0
{% else %}
none
{% endif %}
The first option (100) will be used no matter which trigger occurs if binary_sensor.altandorr_sovrum is ‘on’ (which I presume equates to open.) If binary_sensor.altandorr_sovrum is ‘off’ (which I presume equates to closed), then the value will be 100 if the event is 1002, 50 if the event is 1004, or 0 otherwise (e.g., event 1005.)
Is that what you’re looking for?
EDIT: I updated the first if to make it clearer, and I changed the last elif to else, which is what it should be.
I didn’t get it to work like a wanted your way. Like i said, I know it is wrong but it works.
I always want 1002 to trigger. Doesnt matter if binary sensor is on or off.
But for 1004 and 1005 I only want to allow if binary sensor is off
Ok, I think I misunderstood what you wanted when it comes to binary_sensor.altandorr_sovrum. I thought you wanted that to force 1004 and 1005 to set the cover position to 100. But I think now you want that to simply not allow 1004 and 1005 to do anything.
So if I understand correctly now, I would suggest this:
- alias: Knapp för markis sovrum
trigger:
platform: event
event_type: deconz_event
condition:
condition: template
value_template: >
{% set event = trigger.event.data.event|int %}
{{ trigger.event.data.id == 'lumisensor_switch_6' and
(event == 1002 or
event in [1004, 1005] and
is_state('binary_sensor.altandorr_sovrum', 'off')) }}
action:
service: cover.set_cover_position
entity_id: cover.markis_sovrum_level
data_template:
position: >
{% set event = trigger.event.data.event|int %}
{{ {1002: 100, 1004: 30, 1005: 0}[event] }}
Can anyone help me set the position of my garage door? Anytime mimolite_sensor_2 is “on” i’d like to set the position to 100…anytime it’s off I’d like it set to 0.
Can you tell us something about how switch.fortrezz_mimolite_switch_2 controls the garage door? What happens when it is turned on? What makes it go back off?
Also, what does binary_sensor.fortrezz_mimolite_sensor_2 indicate? I.e., what causes binary_sensor.fortrezz_mimolite_sensor_2 to be on, and what causes it to be off?
For what it is worth, I’m not sure you’ll be able to set the door’s “position” with only a binary sensor. At best, if you can start the door closing, or start the door opening, and stop it, and you know how fast it moves, then you might be able to estimate position. But since you seem to turn the same switch on for opening, closing and stopping, it’s not clear how your system works.
When I turn on “switch.fortrezz_mimolite_switch_2” the door it momentarily sends a signal to the garage door opener. So if I turn the switch on it opens the door, next time I turn the switch on it closes the door.
When the garage door opens “binary_sensor.fortrezz_mimolite_sensor_2” switches to “on”. “off” when the door is closed.
I’m not really concerned about the exact position…I just want the door to know when it’s open or closed. This works fine until I use the garage remote in my car…then the cover loses track if the door is open or close.