Adding First Z-Wave Devices (using Aeotec Z-Stick 7)

Do you know much about how HA handles thermostats? I posted about an issue with my thermostats. Now I realize it might be a Z-Wave issue due to the interference, but I’m wondering about how HA handles the climate and thermostat issues overall.

If you can’t answer this, no problem, but I figure it won’t hurt to ask!

My thermostat has a built in range of 3° minimum between heating and cooling temp. So if I set the cooling at 70°, the heating has to be 67° or lower. I can set both through HA (when it all works), but I also see “Target Temperature” as an option. The thermostat itself doesn’t use that. I’m wondering if HA is smart enough that if I set a Target Temp, it’ll monitor the thermostat and temperature regularly and change the heating and cooling temps as needed or will directly control the thermostat in some other way to keep it at the target temp.

Do you know anything about that?

The target temperature is the temperature you set it to. But with the likes of my thermostat because it is a Generic one that just has a temperature sensor entity that it monitors and a switch entity that it controls, I also have a hystersis (I can’t spell it lol) for below and above the temperature. So it’s basically replicating what your thermostats manage themselves.

If I set my target to 18.5C, the heating will come on if it falls below 18.2C and will switch off after it reaches 18.9C.

So HA will do the monitoring and turning on heating or cooling as needed? In other words, it can take over the function of the thermostat itself?

With my old ISY system, I was eventually planning to write a Python script to handle that. During the summer and winter, it’s easy to just leave one set of automations running, since it’s either heating or cooling and I can just allow time for things to heat up or cool down. As spoiled or coddled as it sounds, 3°, on some days, can make the difference between comfortable and sleeping or sweating and not sleeping. I was planning on writing a script to focus on a range and to work with that 3° range on the thermostat and adjust it up or down as needed.

If HA can do that, then that saves me a good amount of work - providing I can get all the other things working!

1 Like

Yes, I just have a one wire relay board connected to the boiler, and a generic thermostat in home assistant, here is my thermostat in Home Assistant:

climate:
  - platform: generic_thermostat
    name: House
    heater: switch.house_boiler
    target_sensor: sensor.average_house_temperature
    min_temp: 14
    max_temp: 25
    min_cycle_duration:
      minutes: 15
    initial_hvac_mode: "heat"
    away_temp: 16.5
    cold_tolerance: 0.3
    hot_tolerance: 0.3
    keep_alive:
      minutes: 5
    precision: 0.1

As you can see the tolerance for hot and cold is what controls the hysteresis - this is everything Home Assistant needs.

As for Schedy, creating a schedule for summer and winter is very easy and covered in the documentation: The Basics: Static Schedules — hass-apps 0.20200319.0 documentation scroll down to “rules with sub schedules”. Schedy is very easy to use, and as long as you can provide HA with a sensor that is reporting the current temperature in the house, and point it at a switch it can turn on and off - then HA could take over the role of the Thermostat completely.

EDIT:
Here is cooling:

climate:
  - platform: generic_thermostat
    name: Attic_Fans
    heater: switch.aud_attic_fans
    target_sensor: sensor.auditorium_attic_temperature
    min_temp: 14
    max_temp: 40
    min_cycle_duration:
      minutes: 30
    initial_hvac_mode: "cool"
    cold_tolerance: 0.5
    hot_tolerance: 0.5
    target_temp: 16
    ac_mode: true
    precision: 0.1

That’s what I call a “Pondering Post.” I’m going to have to take some time to go over it and “ponder” on it. (Then I can say, “Pinky, are you pondering what I’m pondering?”)

When you talk about one-wire, do you mean the one-wire input on the Pi, or do you mean that’s how the thermostat connects to the HVAC system?

I did see a write-up somewhere on the internet (I’m sure I kept the link) where someone replaced his thermostat with a Raspberry Pi. That was before I was reviewing and checking out HA, so he might have even been using HA as part of that setup. I like that a Pi can do so many things. What frustrates me is that the Pi, itself, is $30-$35US, but by the time I get heatsinks, a case, and a power supply, it’s about $100US. I’m looking into Pi Zero for some uses. You can get them with the pins soldered in place for a pretty low price. Something like that can replace simple sensors for a decent price.

The one wire system, which the Pi can certainly join, is technically a 2 wire system, because there is a ground wire too. But the data and power can run down the same wire.

Our 1 wire system is actually running on Ethernet cable, because it spans 2 buildings. We could have used a Pi with a USB 1wire adaptor, but this was before things like that because popular. So we used an Embedded Systems One Wire Ethernet Server ( 3 channel ) it looks like this https://www.amazon.com/Embedded-Data-Systems-OW-SERVER-Ethernet/dp/B00S8SADV2

And then we have Temperature sensors across the Theatre on the 3 channels. One channel is all the theatre, one channel is the cafe and the foyer. The last channel is for the house - but really only has an 8 channel relay board, and a few temperature sensors on it. One of the temperature sensors is taped to the outgoing heating pipe from the boiler so that we can have a template sensor that turns on when the temperature of the pipe goes above a level, and then I have an alert if the heating switch has been turned on for 5 minutes, but the temperature of the water pipe has not gone above the threshold. Because it means either the boiler pressure is too low, or there is some other problem with the boiler.

The even cheaper way of doing temperature sensing - and we have 3 of them -
get ESP8266 boards ( commonly called NodeMCU ) Wire a DS18b20 to them. ESP Home built in to Home Assistant, will take you the rest of the way.

Here is an example I use, because of where it is situated, I also added a reed sensor so that we have a door contact sensor too.

substitutions:
  device_name: livingroom_thermo
  room_name: living_room
  light_level: '8.5'
  door_room_name: store_room
  thermo_light_switch: switch.store_room
  light_id: 'light.smart_led_light_bulb_level_7'
  dev_ip: '192.168.2.60'
  
esphome:
  name: ${device_name}
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: 'DH-JM'
  password: !secret wifi_password
  domain: '.nptohc.co.uk'
  manual_ip:
    static_ip: ${dev_ip}
    gateway: 192.168.2.254
    subnet: 255.255.255.0
api:
  password: !secret api_password
  reboot_timeout: 15min

# Enable logging
logger:
  level: WARN
time:
  - platform: homeassistant
    id: homeassistant_time
    timezone: 'Europe/London'
    on_time:
      - cron: '0 0 * * * *'
        then:
          - script.execute: status_update
ota:
  password: !secret ota_password
sun:
  latitude: 55.70636
  longitude: -2.46281
dallas:
  - pin: D1
    update_interval: 15s
  
binary_sensor:
  - platform: template
    name: "${room_name} daytime"
    id: ${room_name}_thermo_daytime
    lambda: |-
      if (id(sun_elevation).state < ${light_level}) {
        return false;
      } else {
        return true;
      }
  - platform: gpio
    pin:
      number: D2
      mode: INPUT_PULLUP
      inverted: True
    name: "${door_room_name} door"
    id: "${device_name}_door"
    device_class: door
    on_multi_click:
      - timing:
          - ON for at most 3s
          - OFF for at most 3s
          - ON for at least 0.2s
        then:
          - script.execute: door_override_update
          - homeassistant.service:
              service: light.turn_on
              data:
                entity_id: ${light_id}
      - timing:
          - ON for at least 3.1s
        then:
          - script.execute: door_update
          - if:
              condition:
                - binary_sensor.is_off: ${room_name}_thermo_daytime
                - binary_sensor.is_on: ${device_name}_door
              then:
                - homeassistant.service:
                    service: light.turn_on
                    data:
                      entity_id: ${light_id}
      - timing:
          - OFF for at least 3.1s
        then:
          - script.execute: door_update
      
switch:
  - platform: gpio
    pin:
      number: D6
      mode: OUTPUT
      inverted: True
    name: "thermo_status_led"
    id: ${device_name}_thermo_status_led
  - platform: gpio
    pin:
      number: D7
      mode: OUTPUT
      inverted: True
    name: "boiler_status_led"
    id: ${device_name}_boiler_status_led
  - platform: gpio
    pin: 
      number: D4
      mode: OUTPUT
      inverted: True
    id: status_led
    name: "status_led"
    internal: true
    
script:
  - id: status_update
    then:
      - switch.turn_on: status_led
      - delay: 300ms
      - switch.turn_off: status_led
  - id: door_update
    then:
      - switch.toggle: ${device_name}_thermo_status_led
      - delay: 150ms
      - switch.toggle: ${device_name}_thermo_status_led
      - delay: 150ms
      - switch.toggle: ${device_name}_thermo_status_led
      - delay: 150ms
      - switch.toggle: ${device_name}_thermo_status_led
  - id: door_override_update
    then:
      - switch.toggle: ${device_name}_boiler_status_led
      - delay: 150ms
      - switch.toggle: ${device_name}_boiler_status_led
      - delay: 150ms
      - switch.toggle: ${device_name}_boiler_status_led
      - delay: 150ms
      - switch.toggle: ${device_name}_boiler_status_led

sensor:
  - platform: dallas
    index: 0
    name: "${room_name} temperature uncalibrated"
    filters:
      - filter_out: nan
      - sliding_window_moving_average:
          window_size: 6
          send_every: 4
          send_first_at: 4
      - delta: 0.1
      
    on_value:
      then:
        - script.execute: status_update
    on_raw_value:
      then:
        - sensor.template.publish:
            id: template_temperature
            state: !lambda 'return x;'
  - platform: template
    name: "${room_name} temperature"
    id: "template_temperature"
    filters:
      - filter_out: nan
      - sliding_window_moving_average:
          window_size: 6
          send_every: 4
          send_first_at: 4
      - delta: 0.1
      - calibrate_linear:
        - 0.0 -> 0.0
        - 20.3 -> 18.9
        - 20.4 -> 19.04
        - 20.5 -> 19.185
        - 20.6 -> 19.33
        - 20.7 -> 19.41
        - 20.8 -> 19.59
        - 20.9 -> 19.755
        - 21.0 -> 19.8625
    unit_of_measurement: "°C"
    icon: mdi:thermometer
  - platform: wifi_signal
    name: "${room_name} wifi"
    update_interval: 5s
    filters:
      - sliding_window_moving_average:
          window_size: 12
          send_every: 12
          send_first_at: 6
  - platform: uptime
    name: "${room_name} uptime"
  - platform: sun
    name: "sun_elevation"
    internal: true
    type: elevation
    id: sun_elevation

Now I have extra stuff going on in there than you would need - mostly flashing an LED to confirm that it registered the door being opened or closed or that a period of time has passed since the door was closed, and now the light in the room will be turned off. Additionally there is some detection of the door opening and closing quickly, which enables me to open, close, open within a few seconds to force the room light to turn on when it is dark outside but it’s not night time.

The important bits are:

dallas:
  - pin: D1
    update_interval: 15s
sensor:
  - platform: dallas
    index: 0
    name: "${room_name} temperature uncalibrated"
    filters:
      - filter_out: nan
      - sliding_window_moving_average:
          window_size: 6
          send_every: 4
          send_first_at: 4
      - delta: 0.1

So I filter out values that are nan which means not a number.
I then have a sliding window so that instead of the temperature going up and down in spikes, we get a temperature that is averaged across 6 samples - which at 15sec intervals is 1min 30secs. There is also a delta of 0.1 which means that we only update when the temperature we are going to send to home assistant, has changed since at least 0.1 since we last sent it.

Now in the longer code above you will notice there is calibrate_linear, which enables me to provide Home Assistant with a temperature that is closer to accurate - by providing ESPHome with known temperature values, versus what the Dallas sensor is reporting. ESPHome will then try and scale it’s output based on what temperature values it knows are correct.

Hope this helps a bit.

EDIT:
The 2 LEDs that are connected are red and green. The board has an inbuilt blue LED - which I flash when an update is sent to Home Assistant. The green LED is turned on when the heating switch in Home Assistant is turned on by the climate thermostat. And then the Red LED is turned on when the template sensor in Home assistant which tells us the boiler is working, because the water pipe has gone above 45C. This was the 3 of these that we have around the house, are reporting the heating and boiler status visually.