The State of the Binary_sensor will be recognized correctly (On when pressed, off when not pressed).
LED is Off → when I press the Button, the LED turns on… BUT: It stays on.
The Light entity does not reflect the LED state (on or off)
BUT:
With the light entity, I can controll the light, too.
If the LED turned on (by pushing the button) - And then, I switch on the LED throught the light entity,
I can turn off the LED
Now:
I want the following:
Turning on the LED within the light entity: Should set thje binary_sensor to true (on)
Pushing the Button should switch off the LED and the Light Entity
Pushing the Button should switch on the LED and the light entity… and then I should be able to shut down the light again with the light controll…
thanks
I will do some tests later in the evening when I am at home or over the weekend.
But maybe, I need to explain it a bit more in detail (was on hurry when I wrote the initial post)…
The “Button” is just a simple push/release button - but I would like that it does behave like a switch.
So:
LED is off → Pushing the button, turns on the LED
LED is on → Pushing the button, turns off the LED
this would allow me to have either a controll within the Software, but also on the Hardware itself.
Therefore, I probably need a way to store the current state somehow:
so, that’s an example on how I would write it in the Arduino Software directly:
const int BUTTON_PIN = 13; // Arduino pin GPIO13 on ESP32
const int LED_PIN = 15; // Arduino pin GPIO15 on ESP32
// variables will change:
int state = false; // the current state of LED
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP); // set arduino pin to input pull-up mode
pinMode(LED_PIN, OUTPUT); // set arduino pin to output mode
}
void loop() {
if (digitalRead(BUTTON_PIN) == true) {
state = ! state;
digitalWrite(LED_PIN, state);
}
while (digitalRead(BUTTON_PIN) == true);
delay(50);
}
Except to have an additional SW Option to change the Button / light State.
Ok, so in the case of a momentary switch, you can simplify the setup. Use the on_press trigger only (if you don’t care how long the button is pressed), and then call light.toggle against the light (not the output).