I would like to make the delayed_off value configurable from Home assistant. Is template the right thing for that? How would I need to add it correct. Or better the number component?
Maybe it is possible, but in you case I would consider removing the delays here and create a template sensor in HA with the delays. Unless there is a reason the logic needs to be in the module.
Sure - but there are probably other (better) ways of debouncing your sensor - what is it detecting and what are you doing with it?
You need to write C++ code for your own filter.
First declare a couple of homeassistant text sensors for your delays, then in the binary sensor:
binary_sensor:
- platform: gpio
pin: GPIO33
filters:
- lambda: |-
off_delay = atoi(id(off_delay_sensor).state.cstr());
on_delay = atoi(id(on_delay_sensor).state.cstr());
if x == true { # x is the value of your binary sensor
# some processing that checks last time sensor was turned off and compares it
# that plus the on_delay. If not long enough then
return false; } # leave off
else {
# some processing that checks last time sensor was turned on and compares it
# that plus the off_delay. If not long enough then
return true; } # leave on
}
This is essentially what delayed_on etc do, but you can provide the timings using a HA text sensor.
If you aren’t familiar with C++ programming you may have to go with a different method.
I am debouncing a PIR Sensor that is switch fast between on/off. But with this filter it works as expected. But I want to make the off value configurable, maybe also the on value.
The off_delay_Sensor is a number component or where does the value come from? You writing home assistant text sensor, so the text sensor is send automatically to esphome? or do I need also a text_sensor in esphome?
That’s just a framework - there is a lot of coding to do there…
As I said - you have to define text sensors - and probably global variables and a whole lot of stuff and if you aren’t a C++ programmer I would just stick to the hard coded delays.