I have an Ikea lamp that has a microswitch type button which when clicked toggles the state of the light which I read with a binary sensor.
this is the config I have now:
So switch is D5, binary sensor is D2
What I cannot do is to make such cagelamp1.yaml file that I have only one visible switch, which, when pressed will cause D5 to turn on for 500ms and then turn off, and this visible switch to read the state of D2, and stay with the state of D2 and not the state of D5.
I tried with different lambdas, but I did not make it work, so I pasted here only the basic code to be easier to understand.
Very good looking, but I will have to verify it with a multimeter, when the family is not sleeping and I can take it.
I also did create a variant, much worse looking and I was going to paste it here, because it has a bug: if the physical button is pressed, the light will light up, the binary sensor will detect it, it will trigger the template switch to show that it is on and it will turn on the click switch which will turn off the light: