Rest_command doesn't work when executed with automation

I’m trying to integrate my home heat pump into HA. I’m having problem with automation running rest_command, to set room temperature in heat pump controller. When I run rest_command with Developer tools → Actions the command works, but when the command is run by automation, heat pump will not change its temperature.

Rest command:

  heat_pump_set_temperature:
    url: "http://192.168.1.234/d13output.cgi"
    method: POST
    payload: "id=MV1&MV1_Thi=220"
    content_type: "application/x-www-form-urlencoded"

I hardcoded to send command for 22°C while debugging.

Automation:

- id: set_heat_pump_temperature
  alias: Set Heat Pump Temperature
  description: Adjust temperature via input_number
  triggers:
  - trigger: state
    entity_id: input_number.heat_pump_temperature
  actions:
  - action: rest_command.heat_pump_set_temperature
  mode: single

The trace for this automation gives no error and shows that the rest_command was performed. The debug log for rest_command shows that commands were successful, but heat pump’s settings doesn’t change when the rest_command is run by automation and it works when run by Developer tools → Actions.

It is impossible to say what may or may not be wrong as you have not properly marked up your code, destroying the indentation.

Hi - you need to format your post so we can read your code.

Use preformatted text tags - </> on the posting toolbar. Also have a read of this when you get a chance:

Item 11 is all about formatting…

Ok so I’m fairly certain this is a copy paste error - you need to try again with the yaml preserving the indentation - because yaml syntax is all about indentation…

This is an example from mine:

alias: Front Lights On
initial_state: true
triggers:
  - entity_id: sun.sun
    value_template: "{{ state.attributes.elevation }}"
    below: -1
    trigger: numeric_state
  - entity_id: sensor.front_verandah_lux
    below: 200
    trigger: numeric_state
conditions:
  - condition: time
    after: "17:00:00"
    before: "22:00:00"
  - condition: state
    entity_id: light.front_garden_lights
    state: "off"
actions:
  - entity_id: light.front_garden_lights
    action: light.turn_on

Assuming your yaml is correct, what happens when you run the automation via Automations & scenes, on the Automations tab, select the automation then choose Run actions from the ellipsis menu? Does it give the same result as when you run it from developer tools? If so, then maybe the trigger isn’t working.

No, it still doesn’t work.

Logs shows that the command was executed successfuly but in the second case (logs at 10:00) the heatpump didn’t changed temperature settings.

2025-02-27 09:59:29.726 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Running websocket_api script
2025-02-27 09:59:29.727 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Executing step call service
2025-02-27 09:59:29.763 DEBUG (MainThread) [homeassistant.components.rest_command] Success. Url: http://192.168.1.234/d13output.cgi. Status code: 200. Payload: b'id=MV1&MV1_Thi=220'
2025-02-27 09:59:29.776 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Stop script sequence: done
2025-02-27 10:00:04.350 INFO (MainThread) [homeassistant.components.automation.set_heat_pump_temperature] Set Heat Pump Temperature: Running automation actions
2025-02-27 10:00:04.351 INFO (MainThread) [homeassistant.components.automation.set_heat_pump_temperature] Set Heat Pump Temperature: Executing step call service
2025-02-27 10:00:04.387 DEBUG (MainThread) [homeassistant.components.rest_command] Success. Url: http://192.168.1.234/d13output.cgi. Status code: 200. Payload: b'id=MV1&MV1_Thi=220'

I recorded internet traffic with wireshark, but still don’t understand why the same command works when run with debug tools and doesn’t when run with automation.
This is the trafic when the command was successful: Imgur: The magic of the Internet, and this is when run with automation: Imgur: The magic of the Internet

So you call the action from developer tools and it works, but the same action doesn’t when called manually from the automation… No idea I’m sorry…

Just for giggles - repost your automation yaml. Are you sure that indentation is correct? You didn’t fix it above.

This automations.yaml copied from Code server:

- id: set_heat_pump_temperature
  alias: Set Heat Pump Temperature
  description: Adjust temperature via input_number
  triggers:
    - trigger: state
      entity_id: input_number.heat_pump_temperature
  actions:
    - action: rest_command.heat_pump_set_temperature
  mode: single

HA is running in a Docker container on RaspberryPi, HA version: 2025.2.4

Everything looks fine… It does my head in that all the names are so similar - but that’s just me… :slight_smile: Maybe someone else can spot something.

Shouldn’t make a difference.

Try enabling debug logging for the rest command:

logger:
  logs:
    homeassistant.components.rest_command: debug

and see if that gives any more info.

I alreaddy had it enabeled.

logger:
  default: info
  logs:
    homeassistant.components.rest_command: debug
    homeassistant.components.rest.data: debug

So is there any difference in the logs between the 2 methods of running the action? The home assistant logs, not the traces.

EDIT - I missed your post above - just having a look…

Ok - maybe it’s a timing issue with how HA runs automations and what happens if an action step finishes with commands still outstanding? Just clutching at straws, but what happens if you add - delay: 0:20 after the rest_command step?

It’s still the same as before

- id: set_heat_pump_temperature
  alias: Set Heat Pump Temperature
  description: Adjust temperature via input_number
  triggers:
    - trigger: state
      entity_id: input_number.heat_pump_temperature
  actions:
    - action: rest_command.heat_pump_set_temperature
    - delay: 0:20
  mode: single

Have you still hard coded the temperature? It seems it sends only 22°

I reckon it’s time for GitHub. The RST is coming from HA - I assume because of some timing issue, when run within the automation.

They will probably need a longer log extract and text rather than screenshots of Wireshark - but worth a try.

I hardcoded it so it is one less thing that could be wrong. After every try i check the settings on the heatpump’s webpage and change the temperature to 21°C.

1 Like