Request for help to create an "advanced" automation

Hello everybody

I’d need your help to identify the best way to create the automation I have on my mind. I’m pretty sure I have to use templates, and I’m not good at it at all… Basically this is in summary what I’d like to accomplish:

  • I do have an energy monitoring device which helps to check the power consumption
  • the automation should turn off my climate in case the power consumption goes too high, this action should run only if the climate is running
  • after the power consumption goes back to normal, the automation should then turn back on the climate

Please if somebody would help it will be much appreciated. At least to give me some directions, I’m not expecting to get the code ready to use :slight_smile:

Provide the entity names that will be involved in this automation and the power thresholds for “too high” and “normal”.

1 Like

What are your entities and the relevant attributes?

What is “too high”?

What is “normal”?

Hello guys

sorry you’re right I actually forgot some details…
So the entity names involved are:

  • sensor.interr_generale_current_consumption (the energy monitor power consumption entity)
  • climate.clima_soggiorno (the climate to be turned off and back on)

The thresholds are:

  • normal would be below 2000 W
  • too high would be higher than 3500 W

Thanks a lot for your very quick replies! If I have to provide more information, please let me know !

This is just a preliminary example and will probably require modifications:

- alias: 'High Power - Turn off climate'
  trigger:
  - platform: numeric_state
    entity_id: sensor.interr_generale_current_consumption
    above: 3500
  condition:
  - condition: template
    value_template: "{{ states('climate.clima_soggiorno') != 'off' }}"
  action:
  - service: climate.turn_off
    entity_id: climate.clima_soggiorno

- alias: 'Normal Power - Turn on climate'
  trigger:
  - platform: numeric_state
    entity_id: sensor.interr_generale_current_consumption
    below: 2000
  condition:
  - condition: state
    entity_id: climate.clima_soggiorno
    state: 'off'
  action:
  - service: climate.turn_on
    entity_id: climate.clima_soggiorno

I already know the first automation will require enhancement to handle the situation where the power consumption is already above 3500 and then someone turns on the clima_soggiorno. However, to make that enhancement, I need to know what are the possible states for clima_soggiorno (such as heat, cool, auto, etc).

1 Like

Thanks for your reply.
The first automation I believe is very good. The following are all the possible states of this entity:

hvac_modes: off, heat, cool, fan_only, dry
min_temp: 16
max_temp: 30
target_temp_step: 1
fan_modes: low, min, mid, high, max, auto
current_temperature: 20
temperature: 21
current_humidity: 68.7
fan_mode: low
last_on_operation: heat
device_code: 1522
manufacturer: Hisense
supported_models: DGR11R2
supported_controller: Broadlink
commands_encoding: Base64
friendly_name: Clima Soggiorno
supported_features: 9

as of the second automation instead, I believe that’s going to turn on the climate every time the consumption goes below 2000, and that’s not good as I would need that only in case the previous automation ran. Perhaps this can be used as condition?

Sure, just create an input_boolean and use it as indicator to determine if the climate entity should be turned on.

- alias: 'High Power - Turn off climate'
  trigger:
  - platform: numeric_state
    entity_id: sensor.interr_generale_current_consumption
    above: 3500
  condition:
  - condition: template
    value_template: "{{ states('climate.clima_soggiorno') != 'off' }}"
  action:
  - service: input_boolean.turn_on
    entity_id: input_boolean.high_power
  - service: climate.turn_off
    entity_id: climate.clima_soggiorno

- alias: 'Normal Power - Turn on climate'
  trigger:
  - platform: numeric_state
    entity_id: sensor.interr_generale_current_consumption
    below: 2000
  condition:
  - condition: state
    entity_id: climate.clima_soggiorno
    state: 'off'
  - condition: state
    entity_id: input_boolean.high_power
    state: 'on'
  action:
  - service: input_boolean.turn_off
    entity_id: input_boolean.high_power
  - service: climate.turn_on
    entity_id: climate.clima_soggiorno

Thanks for the idea ! I’ll try that

So I tried the automation and the “Normal Power” doesn’t work. I managed to get it to work by removing the input_boolean condition. What could it be wrong?

How did you define the input_boolean? In the configuration.yaml file or via the UI?

Copied and pasted your code into the automation.yaml file. But now I’m probably getting the reason why it is not working, I have to create the entity first, right ? I’ve never played with it so I’m probably missing something…

Correct. Easiest way is via Configuration > Helpers.

Yeah I figured it out while I was reading your answer… I created it this way:


Going to test it soon.

Thanks a lot again for your help

Tested it, works like a charm. I just needed to add a delay and that’s it.

Many thanks !! :slight_smile:

1 Like