Reading temperature for automation

I want to check a temperature is above 27Degree C
Seems strange but, When making the automation it only gives the option temperature changes (above or below) a setting
If the temperature is already at 29 degree or higher the automation does nothing as it only checks the change
I must be missing something here. I set a time when to start the automation and if temperature is over it does nothing
How to check what the actual temperature is at and act on that. I feel there should be a way of reading the actual temperature, not looking for a transition from one state to another.

You use a condition to check the Temp. But if this is running some kind of heating cooling, then use the generic Thermostat

Hi Arh
Thanks for the reply
I just want to know how do I read the actual temperature
It shows the value on screen but I don’t know how to read that in my very simple temperature control
And not sure if I am missing some simple thing in the automation
I will look at your suggestion

Hi
Just tried the Generic Thermostat. it selects the sensor but can not see my Matter Controller for the air conditoner

If you want to trigger an automation as soon as the temperature exceeds 27 degrees, you must use a time pattern as the trigger and the condition “Temperature > 27 degrees.”

For example, every hour:


description: ""
mode: single
conditions:
  - condition: numeric_state
    entity_id: sensor.xxx_temperature
    above: 27
actions: []
triggers:
  - hours: /1
    trigger: time_pattern

Hi
What I am trying to do is set the AC during the day between 8am to 9pm
This I can do but the temperature sensor in the UI only seems to work if the temperature changes state to over this setting, if it is already over it seems to skip to automation cos the setting seems to be “change state”
I will try the above test for numeric state (need to edit in YAML)
NOTE still learning. I am slow learner…

You use the generic thermost

climate:
  - platform: generic_thermostat
    name: Study
    heater: switch.study_heater
    target_sensor: sensor.study_temperature
    min_temp: 15
    max_temp: 21
    ac_mode: false
    target_temp: 17
    cold_tolerance: 0.3
    hot_tolerance: 0
    min_cycle_duration:
      minutes: 1
    max_cycle_duration:
      minutes: 10
    cycle_cooldown:
      seconds: 30
    keep_alive:
      minutes: 3
    initial_hvac_mode: "off"
    away_temp: 16
    precision: 0.1

Your matter switch goes where it says heater, and then an automation to call the HVAC mode at the time you want.

I want to post what I am doing. how to show the yaml correctly here

This is what I am testing at the moment

alias: Living room ac on
description: ""
triggers: []
conditions:
  - condition: time
    after: "07:30:00"
    before: "21:30:00"
    weekday:
      - sun
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
  - condition: numeric_state
    entity_id: sensor.lroom_temp_temperature
    above: 28
actions:
  - device_id: 55438c514cdd0387ec1aead86ca30ac4
    domain: climate
    entity_id: 22c4e52694bceb2d89d9da61f78d6de3
    type: set_hvac_mode
    hvac_mode: cool
  - delay:
      hours: 0
      minutes: 20
      seconds: 0
      milliseconds: 0
  - device_id: 55438c514cdd0387ec1aead86ca30ac4
    domain: climate
    entity_id: 22c4e52694bceb2d89d9da61f78d6de3
    type: set_hvac_mode
    hvac_mode: "off"
mode: single

Add

  - trigger: state
    entity_id: sensor.lroom_temp_temperature
    not_to:
      - unknown
      - unavailable 
  - trigger: time
    at: "07:30"

This will trigger on all valid numeric changes of your temperature sensor and then the temperature condition checks if it is above 26. The time trigger is in case it is already above 26 at 7:30.

You haven’t got a trigger??

like this with the generic thermostat. It is what it is designed to do. And something similar for off

alias: Thermostat ON
description: ""
triggers:
  - at: "05:15:00"
    trigger: time
  - at: "16:00:00"
    trigger: time
conditions: []
actions:
  - data:
      hvac_mode: "cool"
    target:
      entity_id: climate.temp_thermostat
    action: climate.set_hvac_mode
mode: single

It seems like you are misunderstanding the difference between Triggers and Conditions.

The general method with something like this is, where you have multiple “conditions” that need to be met, is to have a Trigger for each and mirror those triggers in the Conditions.

alias: Living room ac on
description: ""
triggers: 
  - trigger: time
    at: "07:30:00"
  - trigger: numeric_state
    entity_id: sensor.lroom_temp_temperature
    above: 28
    for: #Add your minimum cycle duration here
conditions:
  - condition: time
    after: "07:30:00"
    before: "21:30:00"
  - condition: numeric_state
    entity_id: sensor.lroom_temp_temperature
    above: 28
....

Regarding the actions…

It’s recommended to avoid prolonged delays in automations and scripts. They do not survive restarts so it’s usually best to use a timer or find some other event to trigger the second part of the automation.

A properly-sized air conditioner is only expected to lower the temperature of a room about 0.5°C/hour, so turning it off after just 20 minutes is likely going to cause it to either short cycle or not come back on, because the temperature never got below your set point. Check the owners manual to see what the recommended minimum cycle duration is and then add that to the temperature-based trigger if you’re going to continue down this path.

Does your AC unit not allow you to set a temperature? Most modern, “smart” AC units work best (and usually more efficiently) if you just set the temperature and let their internal controls handle cycles.

Imagine you had a manual thermostat on the wall, does that mean at 8am you would walk over to the thermostat and set one temp and then at 9pm you would walk over and set a different temp?

I will be configuring this Generic Thermostat - Home Assistant
The instructions are simple (so am I) so will need to figure out how and where to set it
When we moved in here there were already Aircon in the rooms office and bedroom are a bit noisy so don’t want then running all the time, the livingroom has no thermostat control so am doing via home assistant till we replace them later in the year

from 8am the aircon will be used, after 9 pm the livingroom is empty so will not switch on

What I do is at 8am set the cooling temp to what I want the room to be at. Then when I leave (or it’s late and I no longer want to run it) set the cooling temp much higher so it doesn’t turn on unless it is quite warm.

I have a fan that uses the same sort of logic. Turn on at 10pm if room temp above 23, turn on and off anytime the temperature crosses 23 between 10pm and 8am, turn off at 8am. So like what you’re trying to achieve, it uses both time and temperature to control the device. I’m not using the generic thermostat, just simple logical triggers for time and a zigbee thermometer in the room.

alias: Bedroom Fan Control
description: Turn fan on and off based on temperature
triggers:
  - trigger: time
    at: "22:00:00"
    id: time_on
  - trigger: time
    at: "08:00:00"
    id: time_off
  - trigger: temperature.crossed_threshold
    target:
      entity_id: sensor.master_bedroom_thermometer_temperature
    options:
      threshold:
        type: above
        value:
          active_choice: number
          number: 23
          unit_of_measurement: °C
    id: temp_on
  - trigger: temperature.crossed_threshold
    target:
      entity_id: sensor.master_bedroom_thermometer_temperature
    options:
      threshold:
        type: below
        value:
          active_choice: number
          number: 23
          unit_of_measurement: °C
    id: temp_off
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id: time_on
          - condition: template
            value_template: >-
              {{ states('sensor.master_bedroom_thermometer_temperature') | float
              >= 23 }}
        sequence:
          - action: switch.turn_on
            metadata: {}
            target:
              entity_id: switch.smart_plug_master_bedroom
            data: {}
      - conditions:
          - condition: trigger
            id: time_off
        sequence:
          - action: switch.turn_off
            metadata: {}
            target:
              entity_id: switch.smart_plug_master_bedroom
            data: {}
      - conditions:
          - condition: trigger
            id: temp_on
          - condition: time
            after: "22:00:00"
            before: "08:00:00"
        sequence:
          - action: switch.turn_on
            metadata: {}
            target:
              entity_id: switch.smart_plug_master_bedroom
            data: {}
      - conditions:
          - condition: trigger
            id: temp_off
          - condition: time
            after: "22:00:00"
            before: "08:00:00"
        sequence:
          - action: switch.turn_off
            metadata: {}
            target:
              entity_id: switch.smart_plug_master_bedroom
            data: {}
mode: single

Hope this helps.

You have your above and below temp to the same value. That might be fine depending on how that temp is set (i.e. how frequently the temp updates and the step size), but that also could lead to frequent on/off cycles, which you probably don’t want.

The generic thermostat has config options for setting the hysteresis and limits on cycle times. And, you get a nice UI for controlling it manually.

Plus, if you use the generic thermostat then your automation is much simpler:

    triggers:
      - trigger: time
        at: "22:00:00"
        id: evening
      - trigger: time
        at: "09:00:00"
    actions:
      - action: climate.set_hvac_mode
        target:
          entity_id: climate.room_thermostat
        data:
          hvac_mode: "{{ 'cool' if trigger.id == 'evening' else 'off' }}"

Or another approach:

    actions:
      - action: climate.set_preset_mode
        target:
          entity_id: climate.room_thermostat
        data:
          preset_mode: "{{ 'comfort' if trigger.id == 'evening' else 'away' }}"

Or, just adjust the temp, of course.

You would want to handle HA restarts, too. Personally, I might have a template sensor triggering on the times and the ha restart for setting the mode and then set the thermostat mode based on that. That way you can just add to that template if, say, a door is left open and you don’t want to cool the outside.

Thanks. I’ll try out the generic thermostat. It genuinely looks simpler.

The generic thermostat has quite a bit of functionality, however for someone just getting started (wanting to control an AC) there are 4 important points:

  • Temperature Input
  • Switch to control AC
  • The target temperature
  • On/Off (Cool/Off) switch on the generic thermostat.

Working through those:

You need some kind of sensor that can report the current temperature in the room to the generic thermostat (thats the only way the thermostat knows the current temperature in the room).

There needs to be some kind of switch that will turn the AC on and off i.e. when the room is too hot the thermostat will switch the AC on, then when the temp is ok it will turn the AC off again - repeating as required.

The target temp is set in the Home Assistant UI, if the room temp is above the target temp the AC is turned on, to cool the room down. There are some extra options to prevent the AC cycling constantly, but you can ignore them to start with.

The On/Off (Cool/Off) switch inside the home assistant UI activates the generic thermostat.
If set to Off the AC unit is guaranteed to be off as well.
If set to On (Cool) then the thermostat uses the temperature and switches the AC on/off to keep the room temperature around the target temperature.


In the simple case of just wanting the temperature to be regulated on a schedule you just need to:

  • Leave the AC control to the generic thermostat (don’t control it separately).
  • Have an automation switch the generic thermostat on (cool) in the morning.
  • Have an automation switch the generic thermostat off in the evening

In the morning the AC may not come on immediately (if the room is too cold / doesn’t require cooling).

However in the evening turning the generic thermostat off, will also stop the AC.