Skip to main content

Last week, in Part 1, I built a device to control and turn on/off my natural gas fireplace.

I did include a short automation using node-red to automatically control the fireplace based on my home’s main thermostate.

This week- I am going to implement the same workflow, directly into home assistant.

Requirements

  1. Automatically set fireplace thermostat N degrees above the main thermostat.
    1. Allow the ability to adjust N from 0 – 10 degrees. (or more, if you wish…)
  2. If the home thermostat is set to heat_cool, ensure we are not heating to the point where the A/C turns on.
  3. Ensure the fireplace is turned off when we leave the house, or goto bed. IE- ensure its not turned on unsupervised.
  4. Turn on the fireplace, when we detect somebody is in the livingroom.

Creating the thermostat

My home thermostat is a Sensi, connected through SmartThings. While- the integration is not perfect, it does allow me to pull in the statistics automatically, with only a ~20 second delay. For this use-case, this is acceptable.

My home thermostat has multiple modes… heat/ heat_cool / cool / fan / off. For this instance, I am only concerned with activating the fireplace when it is set to heat, or heat_cool.

Depending on the mode, slightly different attributes are exposed.

Attributes when thermostat is in heat_cool mode.
Attributes for heat mode.


So- next- while we can technically create our own automations for switching on / off based on conditions… Home Assistant already has us covered with its ‘Generic Thermostat Integration

This integration, accepts a sensor, for current temperature, and will activate/deactivate the switch based on the sensor. It also allows us to ensure we are not short-cycling, and gives a bit of advanced capabilities.

To setup the integration, we just simpally update our configuration.yaml (Sorry- not yet available via the UI.)

Configuration.yaml
climate:
  - platform: generic_thermostat
    name: Fireplace
    heater: switch.fireplace
    target_sensor: sensor.thermostat_temp
    min_temp: 60
    max_temp: 85
    ac_mode: false
    target_temp: 0
    cold_tolerance: 0.3
    hot_tolerance: 0.5
    min_cycle_duration:
      minutes: 2
    keep_alive:
      minutes: 3
    initial_hvac_mode: "off"
    away_temp: 16
    precision: 1.0

However- sensor.thermostat_temp is not something which comes by default with your thermostat integration… but- Home Assistant supports template configurations to make this possible.

sensor:
  - platform: template
    sensors:
      thermostat_temp:
        friendly_name: 'Thermostat Temp'
        value_template: '{{ states.climate.home.attributes["current_temperature"] | float }}'
        unit_of_measurement: 'F'

At this point- we technically have a fully working thermostat, which can be turned on and off automatically via Home Assistant.

Thermostat card within Home Assistant showing our new thermostat.

BUT-

One of my goals for automation, to keep my wife happy, is… Everything automated, must also work manually.

So- to achieve this goal, I will automate setting the fireplace’s setpoint, to a configurable amount above the home thermostat to allow completely automated operation.

As well- the fireplace does have a physical switch to set ON, OFF, or “Automated”

If my wife turns the thermostat up or down, the fireplace will automatically be updated.

Automating the thermostat

Step 1. Create a helper variable

The first step is to create a helper variable. This will hold a value which indicates how many degrees above the home thermostat, to set the fireplace thermostat.

Documentation for “Input Number”

To add a helper, you can either edit the configuration.yaml

OR-

Via the UI, Navigate to: Configuration -> Helpers -> Add New (+ button in the corner) then select “Number”.

I named mine: “Fireplace setpoint increase”, and set its allowed value from 0 – 10, and display as a slider.

Input_Number configuration

Now- you can add this input value to your dashboards, for an easy to use slider.

Step 2. Sync fireplace thermostat to home thermostat.

For this step- I used both an automation, as well as a script.

I want this automation to kick off any time the state on my home thermostat changes.

In the future, I do intend on adding more logic into this automation, however, this will suffice for now. The only action- is to call the script I created (which will be discussed below)

For the script, I gave it a simple name.

However, due to using Jinja2 templates, the action is only editable via yaml. Please see the comments in the code block below.

I do apologize beforehand- some of the templates are a bit messy.

choose:
  - conditions:
      - condition: state
        entity_id: climate.home
        state: heat
    sequence:
      - service: climate.set_temperature
        data_template:
          entity_id: climate.fireplace
# If the thermostat is set to heat only, set the fireplace target temp to N degrees above the setpoint of the home thermostat.. where N is equal to the input_number we created earlier.
          temperature: >
            {{ 
            float(
              state_attr('climate.home','temperature') | float +
              states("input_number.fireplace_setpoint_increase")  | float 
              ) 
            }}
          hvac_mode: heat
  - conditions:
      - condition: state
        entity_id: climate.home
        state: heat_cool
    sequence:
      - service: climate.set_temperature
        data_template:
          entity_id: climate.fireplace
# If the thermostat is set to heat_cool/auto- determine if setpoint_low + our increase >= setpoint_high. If so- subtract 2 degrees from the setpoint_high.
# setpoint_high corresponds to when the A/C would turn on to cool the house.
# Otherwise- set the setpoint to N degrees above setpoint_low, where setpoint_low corresponds to when the heater would normally activate.
          temperature: >
            {% if (float(state_attr('climate.home', 'target_temp_low')) +
            float(states("input_number.fireplace_setpoint_increase"))) <
            float(state_attr("climate.home", 'target_temp_high')) %}
              {{ float(state_attr('climate.home','target_temp_low') + float(states("input_number.fireplace_setpoint_increase"))  ) }}
            {% else %}
              {{ float(state_attr('climate.home','target_temp_high') - 2) }}
            {% endif %}
          hvac_mode: heat
default:
# If the thermostat is not set to either heat, or heat_cool, turn the fireplace off.
  - service: climate.turn_off
    data: {}
    entity_id: climate.fireplace

Step 3 – Presence Detection

I am not going to go into too much depth around Home Assistant’s presence detection in this article, however- I am going to walk through the process of setting up simple automation to disable the fireplace, if nobody is home, or the living room is not populated.

Home Assistant has some rudimentary logic to populate a group’s state. For my purposes, know if anybody is at home, will work just fine.

So- the first step, is to create a new group, to hold the persons I would like to track.

configuration.yaml
# A group of people to track, for presence detection.
all_people:
  name: All People
  icon: mdi:account
  entities:
    - person.me
    - person.wife

After setting up the group, you should be able to see its status within Home Assistant. Do make sure to only place person entities into this new group!

Note- I purposely removed the person’s names, to hide our actual names from the evil people on the internet….

group.all_people now has a state!

Step 4 – Automate turning the fireplace thermostat on.

In addition to looking at the presence, I know typically if somebody is in the house, either the light in the livingroom is on, or the TV is on. When we leave the house, or go outside, these devices are turned off.

So- my triggers are defined as either my TV turns on, or the livingroom light is turned on.

BUT- lets also add a few conditions.

  1. We must not be on vacation.
  2. Presence detection says somebody is at home.

For now- my only action is to turn on the fireplace thermostat.

Step 5 – Automate turning the fireplace thermostat off.

For conditions:

  • The living room TV, ceiling light, and lamp are all off (Means- nobody is in the living room!) OR- they are sitting in the dark….
  • Presence detection detects nobody at home.

Here are the Triggers.

For the conditions, it will be active when EITHER of these conditions are active.

  1. All of the above devices are off
  2. Presence detection says nobody is home.

Since, this looks a bit bloated in the UI, I am going to paste the yaml instead.

condition: or
conditions:
  - condition: and
    conditions:
      - condition: device
        type: is_off
        device_id: 57149eb212fc11eb86297106ad6695af
        entity_id: switch.samsung_6_series_55
        domain: switch
      - condition: state
        entity_id: light.livingroom_ceiling_light
        state: 'off'
      - condition: state
        entity_id: switch.lamp
        state: 'off'
  - condition: not
    conditions:
      - condition: state
        entity_id: group.all_people
        state: home

Lastly- when those conditions are met, turn off the fireplace thermostat.

Summary

While the Node-Red automation from part 1 was effective, I really enjoy having everything in Home Assistant, when/where it makes sense.

In this article, we accomplished a few things:

  1. We create a generic thermostat entity in home assistant, which manages the fireplace directly.
  2. Its temp is automatically set to a configuration temp above the home’s central HVAC thermostat.
  3. The new thermostat entity will be turned on automatically when we detect somebody is in the living room.
  4. The thermostat will be turned off when it is detected nobody is in the living room.

Here is a view of my testing dashboard for this project:

While my penmanship of this article is not perfect, I do hope this article will be of benefit to somebody… or at least get some ideas chourning.