Running HVAC fan from Nest thermostat based on temperature

I have a Nest 3rd gen thermostat. I’m trying to create an automation for the following situation:

  • If the temperature is above 73°F for 30 minutes, AND hvac_mode is set to “heat” OR “heat_cool” AND the sate IS NOT “heating”, turn the fan on and run for 30 minutes
  • If the temperature falls below 73°F within the 30-minute window, turn the fan off

I had read that creating a binary_sensor would help. So, after a lot of trial and error, the template editor finally accepted this:

binary_sensor:
  - platform: template
    sensors:
	  hvac_heat_fan:
	    entity_id:
		  - sensor.living_room_temperature
		  - climate.living_room
		device_class: temperature
		value_template: >-
		  {{ (states('sensor.living_room_temperature')|float > 73)
              and (state_attr('climate.living_room', 'heat'))
              or (state_attr('climate.living_room', 'heat_cool'))
              and not (state_attr('climate.living_room', 'heating')) }}

But when I add the on and off automations below the binary_sensor entry in the yaml, I get tons of errors. I tried moving the file to the packages directory, but then I get a different set of errors (end of the stream or a document separator is expected, property is not allowed, property entity_id is not allowed, property device_class is not allowed, etc).

It’s most likely the case that I’m not understanding the formatting requirements. But I’m at a loss on how to tie this all together and get the on and off automations to work or work together. The automations are below. Any help would be greatly appreciated.

- id: '1574230040095'
  alias: Start fan circulation if temp above 73 for 30 mins
  description: ''
  initial_state: on
  trigger:
    platform: state
    entity_id: binary_sensor.hvac_heat_fan
  to: on
  action:
    - service: climate.set_fan_mode
      data:
      entity_id: climate.living_room
      fan_mode: on
      for: 30

- id: '1574230040096'
  alias: Stop fan circulation if temp falls below 73
  description: ''
  initial_state: on
  trigger:
    platform: state
    entity_id: binary_sensor.hvac_heat_fan
  to: off
  action:
    - service: climate.set_fan_mode
    data:
      entity_id: climate.living_room
      fan_mode: off

Template Sensors ceased to support the entity_id option a long, long time ago. What ancient example did you use as the basis for your Template Sensor?

FWIW, there are so many errors in your automations that I urge you to use the Automation Editor to compose automations as opposed to creating them with a text editor.

If you did use the Automation Editor then there’s been a major copy-paste failure.

Thanks for your input @123. But, not all of us are of a developer or software engineering mindset. As I had prefaced, I may not be understanding the formatting requirements. Since this is a community-driven project, there are times when you have to piece together disparate information to achieve your goal. Since I was unable to, I reached out.

That said, if template sensors are not the way to go, then so be it. I’m happy to try something else. But in this circumstance, the Nest ecosystem hasn’t been the easiest to decipher and work with.

Typically, I use Studio Code Server to help guide me through configuring automations. If it doesn’t work, research usually does. But if Automation Editor will help in this circumstance, then I can leverage that as well.

I never said anyone has to be a software developer. I asked one question (what reference did you use) and I made one recommendation (use the Automation Editor). There’s no software development background needed in either case.

  • Template Sensors no longer support the entity_id option.

  • The format of Template Sensors has changed. Your example’s format is now known as “legacy” and, although it is still supported, one should opt for using the new “modern” format when creating new Template Sensors.

  • When using certain filters like float one should specify a default value. Otherwise, if it can’t convert a value to a floating point number it will result in an error.

  • A Binary Sensor doesn’t support temperature as a device_class.

That’s why I asked where you used as the basis of your Template Sensor because it has led you to create something archaic and flawed.

As for the automations, they contain fundamental syntax errors. I suggest you use the Automation Editor to compose them, then switch the Editor to YAML mode to see the resulting YAML. Compare it to your original examples to spot the differences (for example, to: on is insufficiently indented and so are the last three lines of the service call and the entire service call is in an older format).

Thanks, Taras. Sorry, the original reply seemed a little off-putting at first. I’d have to go back through my history to see what posts I referenced. None of them were direct matches to my situation so I tried to piece together what seemed logical for the end goal.

I haven’t really used the automation editor too much. Mostly because Studio Code Server gives me better feedback (I come from the DOS days). I’ll try porting my config to automation editor and see what I can get out of it. Most of what I’m doing is fairly straightforward, but this one is very specific.