As my first automation, I’d like to have my ecobee turn on the system fan for 10 minutes if it hasn’t run in the past 2 hours. From what I’ve researched so far, this seems more difficult than it sounds
What are some ideas you folks have to accomplish this?
You could trigger on the state.last_changed attribute of the fan and compare it to the current time like with something like this {{ as_timestamp(now()) - as_timestamp(states(sensor.mysensor.last_changed)) > 7200 }}
Thanks. After some more research I’ve come up with the code below. The ecobee fan status is a state attribute. I haven’t been able to get this to work, however. It’s complaining about the “for:” in the trigger. According to the documentation that should work?
@Jer78 is right… spacing is key. After you verify that your spacing is correct, it might be that the actual template trigger won’t fire. This is an issue I have run into, and if you search the forum, you will find that we are not unique. For whatever reason, creating a trigger based on a template sometimes won’t fire, even if that same template is valid and you can make it “work” in the Developer tools.
What I did for my automation that required a template was to simply trigger off of time and use the template as a condition. In your case you can’t trigger off of time, but you could trigger off of something like @Tinkerer said. Namely your fans state and how long it has been in state.
@Jer78, @ammdc7 Thank you. That spacing issue was just a problem with how I formatted it in my post, not in the actual file. It turns out the real issue was that I was editing auomations.yaml through an SMB share in N++, and somehow the file format got switched to Windows/DOS. I changed it back to UNIX and saved the file. Started working. I spent an embarassing amount of time on that mistake
I took @Tinkerer’s advice and changed the template to this:
I think that this is the issue I was referring to earlier… There are a few of us here on the forum that can’t get template triggers to work. You might want to consider wrapping that template into a sensor and triggering off of that. There are a few different options you have, but either a sensor or time trigger would be a good option in my mind.
If you want to test to make sure the template is valid, you can use the Developer tools on the frontend. Let me know if you’re not familiar with those and we’ll get you squared away.
sensor:
- platform: template
sensors:
ecobee_fan:
friendly_name: "Furnace Fan State"
value_template: "{{ states.climate.main_floor.attributes.fan }}"
automation:
- alias: "Automated air circulation"
trigger:
- platform: state
entity_id: sensor.ecobee_fan
to: 'off'
for:
minutes: 120
This seems to work well. I’m curious about how triggers work, however. Let’s say the fan is off, and has been for several hours. If I restart HASS and the automation starts up with fan == off it appears that even after the minutes:120 has been met, the trigger doesn’t fire because it doesn’t start until it sees the state change. This isn’t a huge deal for this scenario, the automation just won’t start until the furnace has come on once. But I’m curious if there is any way to fire a trigger based off a condition without a state having to change?
I’m fairly confident it’ll behave as expected, well, other than it’ll be 120 minutes after the startup of HA (so if you keep restarting HA it’ll never happen). That’s because looking at the startup logs, sensors start as unknown or None.
I have asked the question on Discord though, to check that I’m reading that right.