Automation Triggers

So I just rewriting some of my automations to trigger off the outside temp instead of the season and was wondering if there is a better way to handle updating a single variable in multiple files (without creating a input_variable if possible)

Basically all my thermostat automations are a variation on this

id: Thermostat AC up at night
alias: Thermostat AC up at night
initial_state: 'on'
trigger:
  - platform: time
    at: "23:00:00"
condition:
  - condition: numeric_state
    entity_id: 'sensor.dark_sky_temperature_high_0d'
    above: 85
action:
  - service: climate.set_temperature
    data:
      entity_id: 2gig_technologies_ct101_thermostat_iris_cooling_1
      temperature: 75

and I’d like to be able to just have the two temps be pulled from a central location instead of having to update 5-10 different files to adjust the trigger point / set points.

Side note I’m not even 100% sure this works since I just changed it from checking the season (summer/winter) and to using the high/low temp for the day but I’m not at my actual server to test it. so comments on that would be helpful.

Also I do not want to use Node Red so please don’t suggest it.

If you mean without creating an input_number to hold the temperature threshold, then you won’t want my suggestion:

condition:
  - condition: template
    value_template: >
      {{ states('sensor.dark_sky_temperature_high_0d') | float >=
         states('input_number.threshold') | float }}
1 Like

Use an input_number for your desired temperatures.

Make a script that can take in the temperature sensor entity and climate entity as variables.

script:
  set_thermostat:
    sequence:
      - condition: template
        value_template: >
          {{ states(sensor) | float > states('input_number.temp_threshold') | float }}
      - service: climate.set_temperature
        data_template:
          entity_id: >
            {{ thermostat }}
          temperature: >
            {{ states('input_number.temp_setpoint') |float }}
automation:
  alias: Thermostat Automation
  trigger:
    - platform: time
      at: '23:00:00'
  action:
    - service: script.set_thermostat
      data:
        sensor: sensor.dark_sky_temperature_high_0d
        thermostat: climate.2gig_technologies_ct101_thermostat_iris_cooling_1
    - service: script.set_thermostat
      data:
        sensor: sensor.another_sensor
        thermostat: climate.another_thermostat

Sniped by faster typers :slight_smile: But posting anyway.

1 Like

I hadn’t thought of using a script before (haven’t needed them for anything else so haven’t really read about them) but I’ll be reading up on them now. Might simplify a few things.

And yeah I meant input_number.

Thanks for the suggestions I’ll be going over them.

Anything I find myself doing more than, say, twice and perhaps only slightly differently, I immediately think about putting in a script.

May I ask why you don’t want to use an input_number?

So the rules of this game exclude the use of an input_number? OK, how about an input_text? Or are all things beginning with the word ‘input’ forbidden? If so, you’ll need to find something else to store the threshold value. Although Home Assistant does not support global variables, there are two custom components available that provide this feature.

From my perspective, an input_number that you have an initial value set for, and that you don’t expose in the UI, is basically a global constant as long as you don’t write any automations that change it.

Personal choice really.

I feel there should be a way to do a global variable that isn’t an input. Once I get everything set up and the right temps figured out I don’t foresee changing them. If there isn’t a way to do a global variable without using an input_number then I’ll do that more wanted to know if there was a better way that I was not yet aware of.