It’s based off of the work I did on the original dimmer code. I had always thought this device had potential to do more but hadn’t had the time to figure out the details and write the code until recently.
I have a couple of these in my bathrooms and love the idea. No matter what I set the fan to do, it turns off after 10 minutes. Any idea why? Thanks for your work!
Do you mean when you turn it on from Home Assistant?
If so, that is mentioned on the github readme: “Turning on from Home Assistant will start a 10 minute timer.”
This code was written long before ESPHome offered the ‘number component’. I don’t currently have time to add in support for it but feel free to make a fork and give it a shot.
Recently, I wanted to be able to run the fan for 30m from Home Assistant (automatic fan for showers, based on humidity) and came up with some drop-in code that you can add into to your own yaml if you wish.
####################################################
# Add missing info under the appropriate headings: #
# no need to edit, just drop it into existing yaml #
# only add missing info, do not duplicate headings #
####################################################
api:
services:
- service: timer_30_minutes
then:
- script.execute: timer_30_minutes
script:
- id: timer_30_minutes
then:
# https://esphome.io/guides/automations.html
- lambda: |-
// if the fan is off, turn it on
if (id(binary_fan).state == false) {
auto call = id(binary_fan).turn_on();
call.perform();
}
// change the time remaining
id(timer) = 30;
- logger.log:
format: "Script timer_30_minutes called. The timer value is now %d"
args: ['id(timer)']
##################################################
# Home Assistant Automation example: #
# you will need to edit #
# service #
# trigger > entity_id #
# action > device_id, entity_id #
##################################################
alias: Upstairs Bathroom Fan - Auto for Showers
description: Run the fan for 30 minutes when humidity rises above the specified value.
trigger:
- platform: numeric_state
entity_id: sensor.upstairs_bathroom_humidity
above: '70'
condition: []
action:
- service: esphome.upstairs_bathroom_fan_timer_30_minutes
- wait_for_trigger:
- platform: device
type: turned_off
device_id: 5d2d8957b8854c4a8fd9125f6c62ad87
entity_id: fan.upstairs_bathroom_fan
domain: fan
mode: single
Not really sure why that would be happening unless you flashed them to ESPHome from another firmware while they were already installed.
I have noticed, with quite a few devices, when changing firmware (Stock to Tasmota, Stock to ESPHome, Tasmota to Esphome, etc) that the device needs a full power-cycle (unplug & replug, toggle circut breaker, etc) before it starts acting normally.
If you changed firmwares while they were already installed, try toggling the circuit breaker off and back on. I typically prepare, flash and test devices before installing them in their final location just to be sure everything is acting as expected.
Otherwise, not really sure what would be causing that. I know of 2 people, who live nearby, who also use these as a fan-timer and they are using the exact same code without issue.
Honestly, it sounds a lot like the device just needs a full power-cycle.
If you try that and it’s still not working as expected then open the ESPHome addon and watch the logs for the device. It should be reporting every time the timer value changes, button-presses, etc.
By viewing the logs while the device operates you should be able to get a pretty good idea of what’s happening, or not happening.