Automation using value template -- I think

Hi. I’ve been using HA for a few years and learn more and more all the time. I think what I need involves a value template but I don’t know enough about it to know what to ask so I will just summarize what I want to do:

I have a couple of Zigbee thermostats that can be kinda flaky but aren’t so bad that I am ready to replace them. The problem is that they do not always accept the setpoint that is sent to them so things get out of wack.

I thought I would change my automations from setting the setpoint and have them set a helper variable instead and then write another automation that executes every few minutes makes sure the setpoint matches the variable. That’s where I am stuck. I can’t seem to write a automation that checks to make sure the setpoint and the variable match and changes the setpoint if they do not. I think it has something do do with a value template but I’m not sure.

Any help you can offer will be appreciated.

Try just triggering when the set point and helper are different.

trigger:
  platform: template
  value_template: "{{ state_attr('climate.your_thermostat', 'target_temp') != states('input_number.your_target_temp') }}"
action:
  service: climate.set_temperature
    data_template:
      entity_id: climate.your_thermostat
      temperature: "{{ states('input_number.your_target_temp') }}"

@tom_l – That makes sense and is more efficient than my idea. I will give this a try and let you know how it goes.

Thanks!

Thinking about it, I don’t think it will solve your problem. Say the two values are different, the automation triggers, tries to set the temp but fails. The template remains ‘true’ and the automation does not re-trigger.

I’d add a time pattern trigger as well and use the trigger template in a template condition.

Additional benefit – This should keep people from messing with the thermostat since it will be changed right back if they do.

1 Like

Ha. Yes it will.

Got it. Makes sense. Thanks again.

The main thing is you have a template to experiment with.

1 Like

@tom_l, Well, I’ve been trying to make this work for a while but no dice. Probably a syntax thing. This is what I have:

- id: '1587088885443'
  alias: East Cool Setpoint
  description: ''
  trigger:
  - platform: template
    value_template: "{{ state_attr('climate.thermostat_east', 'target_temp_high')
      != states('input_number.thermostat_east_cool_setting') }}"
  condition: []
  action:
  - data_template:
      target_temp_high: "{{ states('input_number.thermostat_east_cool_setting') }}"
    entity_id: climate.thermostat_east
    service: climate.set_temperature

And I keep getting this error:

East Cool Setpoint: Error executing script. Invalid data for call_service at pos 1: some but not all values in the same group of inclusion 'temperature' @ data[<temperature>]

What am I doing wrong?

It seems to me that a lot of people have issues with setting thermostats.

But why do you want to ?

I use a “generic_thermostat” in software and simply pass it a value for what it’s “setpoint” should be (for that time of day, occupancy etc.) and users need to know where that value is stored/controlled from.
It also allows your thermostat to report on simple time basis or on delta T (saves batteries).

@Mutt – I’m not sure what you are saying. If you read the thread, it should be clear is that my question is about how to write the automation I want. My thermostat is fine apart from its inherent flakiness which has nothing to do with automations or HA in general.

Sorry, but the whole thread is predicated upon the difficulty you have in setting the thermostat value.
I’m saying that if you do the thermostat in software it is a lot easier as then you can ignore the thermostat part of it and just use it as the driving sensor

I don’t follow. How would doing it in software address my physical thermostat’s tendency to not accept commands every time they are sent?

Okay, I shall try to say it one more time.
Your physical thermostat senses the ambient temperature in its location, it has a set point, it has a virtual switch that changes ‘sense’ according to whether it believes the ‘heater’ should be on or off.
So read the sensor, into a generic thermostat, ignore the “physical thermostat’s thermostat” and it’s virtual switch.
Write to the generic thermostat’s setpoint and use the output to drive your actual heater.

To make this clear, I have a z_wave thermostat (it could be on any type though) it has a setpoint, I don’t know what it is because I don’t care, but the software thermostat (in HA) accepts the setpoint I feed it, to control my heating 1. If the house is unoccupied 2 there is a window or door open, 3. it’s day or 4. it’s night.
If door open (I’m not heating the outside world) so 4°C
If no one’s home 12°C
If day 17°C
Evening 19°C
Night 18°C

Thanks for the explanation but this is not what I’m trying to accomplish here. Maybe I haven’t been clear.

That error means you are missing required options for the service call.
See: Climate - Home Assistant

Thanks. Will look into it.