vith
(vith)
April 4, 2024, 1:26pm
1
I want to create a boolean AND function.
2inputs , 1output
only when the 2inputs are on , then the output is on.
i have a yaml , but actualy it is not 100% what i want to achieve.
because there is a delay used.
Question 1 : is it possible in an automatisation to achieve this boolean algabra ?
Question 2 : is it possible in 1 automatisation ?
kind regards ,
alias: and gate
description: ""
trigger:
- platform: state
entity_id:
- input_boolean.a1
to: "on"
- platform: state
entity_id:
- input_boolean.a2
to: "on"
condition:
- condition: and
conditions:
- condition: state
entity_id: input_boolean.a1
state: "on"
- condition: state
entity_id: input_boolean.a2
state: "on"
action:
- service: input_boolean.turn_on
data: {}
target:
entity_id: input_boolean.out
- delay:
hours: 0
minutes: 0
seconds: 3
milliseconds: 0
- service: input_boolean.turn_off
data: {}
target:
entity_id: input_boolean.out
mode: restart
francisp
(Francis)
April 4, 2024, 1:31pm
2
Conditions are ‘and’ by default.
alias: and gate
description: ""
trigger:
- platform: state
entity_id:
- input_boolean.a1
to: "on"
- platform: state
entity_id:
- input_boolean.a2
to: "on"
condition:
- condition: state
entity_id: input_boolean.a1
state: "on"
- condition: state
entity_id: input_boolean.a2
state: "on"
action:
- service: input_boolean.turn_on
data: {}
target:
entity_id: input_boolean.out
- delay:
hours: 0
minutes: 0
seconds: 3
milliseconds: 0
- service: input_boolean.turn_off
data: {}
target:
entity_id: input_boolean.out
mode: restart
tom_l
April 5, 2024, 1:44am
3
There is no need for an automation. Use a legacy group, just set the all
option to true
.
group:
ip_booleans:
name: "ANDed IP Booleans"
all: true # both must be on for on state
entities:
- input_boolean.a1
- input_boolean.a1
mekaneck
(Rick Auch)
April 5, 2024, 12:31pm
4
Tom’s suggestion is the best way to implement what you want. But if you are wanting to learn how to do that in an automation just for the sake of learning, here is how you could achieve it.
Note that I use the choose
function instead of an if
-then
statement but either way would work.
alias: and gate
description: ""
trigger:
- platform: state
entity_id:
- input_boolean.a1
- input_boolean.a2
condition: []
action:
- choose:
- conditions:
- condition: state
entity_id: input_boolean.a1
state: "on"
- condition: state
entity_id: input_boolean.a2
state: "on"
sequence:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.out
default:
- service: input_boolean.turn_off
target:
entity_id: input_boolean.out
mode: restart
1 Like
vith
(vith)
April 15, 2024, 11:31am
5