How do I change a Heat Pump target temperature depending on a sensor?

Hello, so I am trying to control my heat pump depending on electricity prices. If the price goes above x, lower the target temperature. I have managed to get a Lovelace card thermostat to do this. But how can I automate it?
The heat pump communicates via mqtt, and I can see all correct temperatures and so on in HA at the moment. Here is the part in configuration.yaml

climate:
  - platform: mqtt
    unique_id: room_temp_setting
    modes:
    current_temperature_topic: "macadress/HP/0203"
    temperature_state_topic: "macadress/HP/0203"
    temperature_command_topic: "macadress/HP/SET/0203"
    min_temp: 13
    max_temp: 26
    temp_step: 1
    name: "Room temp setting"

The electricity prices are within an entity
sensor.nordpool_kwh_se2_sek_3_10_025
with max, min, and mean, as well as
sensor.nordpool_today_h*
with pricing for each hour.

Thankful for help and feedback!

The following automation yaml would control the heat pump when there is a change in the hourly price.

alias: Temperature change
description: ''
mode: single
trigger:
  - platform: state
    entity_id: sensor.nordpool_today_h*
condition: []
action:
  - choose:
      - conditions:
          - condition: numeric_state
            entity_id: sensor.nordpool_today_h*
            above: x
        sequence:
          - service: climate.set_temperature
            data:
              temperature: 24
            entity_id: climate.heat_pump
      - conditions:
          - condition: numeric_state
            entity_id: sensor.nordpool_today_h*
            below: x
        sequence:
          - service: climate.set_temperature
            data:
              temperature: 24
            entity_id: climate.heat_pump
    default: []

You will have to edit the entity ids and also the temperature values for heat pump and the sensors. If there is anthing we can tweak it.

This worked directly, amazing! I was so sure I had to include some mqtt code in the automation. But I guess that is included already. There are definitely more things I would like to do with it, like turning the warm water off and so on. But that’s a heat pump issue.
Thank you very much!

1 Like