Automation and heater : what do I miss?

Hello,

I think I missed something important to understand the concept.
I read Generic_Thermostat, Climate and other doc, I looked some topics and another websites explaining how they configured their Home Assistant, but I still can’t success in making my automation work. (maybe I have my old Domoticz habit since I switched to Home Assistant 2 days ago).

My server : HomeAssistant core on Raspberry pi
Main hardware : RFXCom
Main devices for my issues : switch on/off on the heater that switch the mode of the heater between eco (7°C celsius) and main mode (19°C celsius).

I added the switches and sensors with success into my configuration.yaml :

rfxtrx:
  device: /dev/ttyUSB0
  automatic_add: false
  debug: true
  devices:
    # Sensor room
    [HIDDEN]:
    # Switch room
    [HIDDEN]:

My switch being inverted, I made a template :

switch:
  - platform: template
    switches:
      switch_room_inverted:
        friendly_name: "Switch Room not inverted"
        value_template: "{{ is_state('[HIDDEN]', 'off') }}"
        turn_on:
          service: switch.turn_off
          data:
            entity_id: [HIDDEN]
        turn_off:
          service: switch.turn_on
          data:
            entity_id: [HIDDEN]

At this time, manually, I used the switch to turn off and off the heater and it works fine.

Then, I discovered the concept of generic thermostat and loved it, so I create one :

  - platform: generic_thermostat
    name: "Thermostat room"
    heater: switch_room_inverted
    target_sensor: sensor.room_temperature
    min_temp: 18
    max_temp: 20
    ac_mode: false
    target_temp: 19
    cold_tolerance: 0.3
    hot_tolerance: 0
    min_cycle_duration:
      seconds: 5
    keep_alive:
      minutes: 3
    initial_hvac_mode: "off"
    away_temp: 7
    precision: 0.1

So I wanted to automate the turn on during the “night” and turn off during the “day”. I tried many things without success (turn on/off the switch, turn on/off the climate thermostat, set hvac_mode or finally, set_preset_mode), but it never works.
This is my latest attempt :

- id: '[HIDDEN]'
  alias: Turn on heater room
  description: ''
  trigger:
  - platform: state
    entity_id: climate.thermostat_room
    attribute: current_temperature
    from: '7'
    to: '18'
  condition: []
  action:
  - service: climate.set_preset_mode
    data:
      preset_mode: none
    entity_id: climate.thermostat_room
  mode: single
- id: '[HIDDEN]'
  alias: Turn off heater room
  description: ''
  trigger:
  - platform: state
    entity_id: climate.thermostat_room
    attribute: current_temperature
    from: '18'
    to: '30'
  condition: []
  action:
  - service: climate.set_preset_mode
    entity_id: climate.thermostat_room
    data:
      preset_mode: away

As you can see, I even remove time conditions in order to understand what’s wrong.
What I don’t understand is that, during most of my tests, when I clicked on “Execute” on my automations, it does exactly what I want. This last configuration I show you works great when I click on “Execute” (when I clicked on the “Turn off heater”, the Thermostat goes in “Away mode” and turn off the switch) but it’s never executed automatically.
What do I miss, please ?

Thank you in advance for your help ! Have a good evening

Your automation will only trigger when the current temperature changes from 7 to 18 directly with no steps in between. This seems unlikely to ever happen. Perhaps you meant to test for a target temperature change instead?

Okay, this is my mistake.
I wanted to give a slot temperature where it should be turned on.
Example :

  • current temperature below 18 : turn on
  • current temperature above 18.5 : turn off

Use the numeric state trigger instead.

Hello,

Thank you, it seems to be what I need ! I read too fast and didn’t understat that the state is not a slot but a straight change of state from A to B.

Now, I want to add the condition of hour (always turned off during the day, but turn on at night if it’s below a certain temperature).
I already tried the first part, turned off during the day, no matter what, but it’s not triggered :confused:

- id: '[HIDDEN]'
  alias: Turn off heater during the day
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: climate.thermostat_room
    attribute: current_temperature
    above: '16'
    below: '32'
  condition:
  - condition: time
    after: 08:00
    before: '19:00'
  action:
  - service: climate.set_preset_mode
    entity_id: climate.thermostat_room
    data:
      preset_mode: away
  mode: single

Could you help me, please ?
Thank you in advance.

I don’t understand : i’ve got my thermostat inactive and away, but it displays the target_temp and it’s in an “heating” mode…

image

  - platform: generic_thermostat
    name: "Thermostat room"
    heater: switch_room_inverted
    target_sensor: sensor.room_temperature
    min_temp: 18
    max_temp: 20
    ac_mode: false
    target_temp: 19
    cold_tolerance: 0.3
    hot_tolerance: 0
    min_cycle_duration:
      seconds: 5
    keep_alive:
      minutes: 3
    initial_hvac_mode: "off"
    away_temp: 7
    precision: 0.1