I have multiple binary sensors ( buttons ). I would like each of them to a toggle an output GPIO ( relay ). As there are many of them, I would like to execute a script with parameters when a button was pressed. The buttons are defined as:
binary_sensor:
- platform: gpio
id: "section_1_button"
name: "Section 1 button"
pin:
number: ${button_1}
mode:
input: true
on_press:
then:
- lambda: id(valve_button_pressed)->execute(*section_1_valve);
The relays are defined as:
- platform: gpio
name: "Section 1 valve"
id: "section_1_valve"
pin:
number: ${valve_1}
inverted: true
restore_mode: ALWAYS_OFF
So far so good. But I have a problem with the script definition. I can have it like this:
script:
- id: "valve_button_pressed"
parameters:
valve: 'gpio::GPIOSwitch'
then:
- lambda: valve.toggle();
In this case the relay is always switched on and it always reports its state as OFF.
In case I define it as
- lambda: id(section_1_valve).toggle();
It works great - the relays witches on and off and it reports correct state.
Please, could you advice:
- What is right way using a switch as a parameter?
- Is there a way, how to use the parameter in construction:
switch.toggle: valve
?