Hi, I’ve got cover and measurement of motor current. My idea is to make “end switch” and “collision detection” by current. Since I don’t want send new value to HA every second, I put there filter. Its side effect is detect collision after some duration.
- platform: ina226
address: 0x40
shunt_resistance: 0.1 ohm
update_interval: 1s
max_current: 0.5A
current:
name: "hen door current"
id: hendoor_current
filters:
- sliding_window_moving_average:
window_size: 8
send_every: 1
on_value:
lambda: |-
if (id(hendoor_current).state > 0.055) {
if (id(hendoor).current_operation == COVER_OPERATION_CLOSING) {
id(hendoor_current).publish_state(0);
id(hendoor).open();
}
else if (id(hendoor).current_operation == COVER_OPERATION_OPENING)
id(hendoor).stop();
}
During closing I’d like reverse motor. It’s partially working, but I need to reset filter window to 0 to not stop motor in next run because of filtered value is still high. Partial solution is to publish state 0, but it only lowers value by 1/8 (window size). May be I can publish state 8 times, but it’s messy solution. Is there a function to reset it?
Or how to ignore values in if statement for particular time. It would be helpfull for “end switch” - cover has end switches connected in series with motor and the end positions can be detected by near zero current.
Any suggestion?
Thanks
Jiri