Hello. I have been converting my devices to ESPHome from Tasmota. However, for the life of me I could not replicate Tasmota’s pulsetime functionality, mainly because:
If the switch receives a turn_on request while it is already on then the on_turn_on action is not triggered. It is only triggered if switching from off to on.
Basically, the template switch is now a “shadow switch” for the real internal switch.
And now when the switch is turned on, this is what happens:
11:25:23 [D] [sensor:093] 'Uptime': Sending state 47.52600 s with 0 decimals of accuracy
11:25:24 [D] [switch:012] 'Relay1' Turning ON.
11:25:24 [D] [switch:012] 'Internal Relay1' Turning ON.
11:25:24 [D] [switch:055] 'Internal Relay1': Sending state ON
11:25:24 [D] [switch:055] 'Relay1': Sending state ON
And when the switch is turned on and it is already on, this is what happens:
It is a little convoluted and you could improve a lot. First off, Switch is the wrong platform to use if your attempting to make an “internal relay”. You need to be using a binary sensor which is much more appropriate for this situation. Even when you are using a physical button/switch you’ll use binary_sensor most of the time, not Switch.
This simply gives reads the state of a gpio and when turned ON or Pressed it sends a command to execute your script which will then restart because you set
When only one PIR controls a switch, and I want the switch to turn off after 10 of the PIR clearing, I could simply put that in HA automation (turn switch off 10 mins after PIR goes to on). If the PIR detects motion again within the 10 min, the automation takes care of this and resets the timer.
However, I have a switch that is controller by two PIRs. Programming this in an automation would be difficult. Instead, any of the PIRs can turn on the switch, and the switch turns itself off after 10 min of no re-activation . Get it?
I read your suggestion again. Unfortunately, it won’s work. There is no “press” action in this case – the relay is activated by an external action (PIR sensor), and a turn_on by that action does not activate on_press.
My solution works.
It would be easier, though, if ESPHome implemented a PulseTime function like Tasmota.
Dont get hung up on definitions like, button, switch, binary_sensor, PIR sensor, etc. They all have different names and different purposes but, to an esp board they are all identical and the esp cant tell a button and a PIR sensor apart, they look identical to the esp. All of them are “binary” they only have 2 states On/Off or High/Low and most things will require you set them up as a binary_sensor.