No, I think you must not have used the </> button to format the code.
I think you are nearly there, the input_number looks okay (but the numbers a bit wild, asuume minutes and go for 1 to 20 but it’s your toilet, step of 30 though ??? ). The automation is a bit off.
There are many ways to do this but the simplest is : -
automation:
- alias: 'Toilet fan control'
trigger:
- platform: state
entity_id: fan.toilet_fan
to: 'on'
action:
- delay: "00:{{ states('input_number.toiletfan_input') | int }}:00"
- service: fan.turn_off
entity_id: fan.toilet_fan
Do you really have a fan domain ? I just have switches
Looking at this I have no idea why I cast the number to int, but I always have
I usually have the fan come on with the light, and go off 10 mins after the light goes out
I would do this with a script, similar to what petro wrote here. The problem with the delay is when the fan get’s turned on again during the delay. This may never be the case for OP, but for other similar automations. Just my 2 cents xD
No I agree, and my light/fan timers use scripts too but I’m pitching this at his level.
Let him get comfortable with that and then we’ll address bypassing timer issues
Trug I’m not using a timer here, I’m using a delay
And yes HA stores input numbers as strings.
My point here was that I was just going to use it in a string anyway, so why bother with the int ??? (that’s a rhetorical question BTW)
I tried with a delay earlier but didn’t work for me so dont know where i went wrong. It works with the delay now so thanks for that.
Now i will be looking at trying the scipt that pedro made here (thanks @Burningstone)
As to the Domain. Yes i have a fan domain… the domain has a lot of fancy fan funktions. But in reality im just talking to a switch so i might change this.
Regarding the stepsize @Mutt. Yes these were just choosen a bit random. But they will be relatively high until i get my humidity sensor connected. Thnaks for the help
Don’t try to run before you can walk, get this working and we’ll enhance it.
The point is the format and the way it is constructed, this happens to that, then we call a delay, then we act on this to turn it off. Its not a formula, or a construct from another piece of software, it’s a logical sequence.
Kobainer, did you get it working.?
Have you discovered the issues with it ?
Do you want to adapt/extend it.?
If you post your current code (make sure it looks like mine ie the format) we can work from that point.
It worked really nicely with the delay. Don’t know where i made the mistake first time i tried the delay.
Tonight i’ll look into scenes to expand it. I’ll make a post later when i worked a bit on it myself first… either to ask for help or share how i expanded @Mutt
Tomorrow my ZigBee hub and humidity sensors arrive. Then i’ll start implementing them aswell.
Tinkering with all this is so much fun, to bad i have to wait for the family to sleep
I have a near identical code for my fan, as Mutt had posted, so I’m not going to pin it here. But as far as the reason why your code didn’t work. When I was playing with input sliders I had noticed that I had to cast values to integer with the |int operand otherwise they are coming as floats and the delay will not work. You can test this in the Developer Tools > Template.
This is then particularly relevant when you concatenate values as in 00:{{ states('input_number.toiletfan_input') | int }}:00.