YAML Script (suddenly) not working for certain Switchbot API commands

Hi

Have setup HA successfully and haven’t touched it in awhile, so a bit rusty and not quite sure how to troubleshoot.

I have Switchbot Hubs (with the IR transmitter) integrated with HA. This is used to control the aircon. The last time the API commands were confirmed to work was in November 2024 (it’s been cold since so hasn’t been a need to switch on the aircon).

Since then, the script doesn’t seem to run at all.

As a first step, I’ve confirmed the problem is specific to the script for the aircon (eg. API commands for other devices such as the curtains do work).

Much appreciated if anyone could shed some light. My truncated code below (please let me know if there’s anything relevant I should post)

configuration.yaml:

rest_command:
  switchbot_device_command:
    url: "https://api.switch-bot.com/v1.0/devices/{{ deviceId }}/commands"
    method: post
    content_type: "application/json"
    headers:
      Authorization: !secret switchbot_api
    payload: '{"command": "{{ command }}","parameter": "{{ parameter }}"}'
  switchbot_irdevice_command:
    url: "https://api.switch-bot.com/v1.0/devices/{{ deviceId }}/commands"
    method: post
    content_type: "application/json"
    headers:
      Authorization: !secret switchbot_api
    payload: '{"command": "{{ command }}","parameter": "{{ parameter }}", "commandType": "{{ commandType }}"}'

climate:
  - platform: climate_template
    name: Study
    unique_id: Study

    hvac_mode_template: >
      {% if states('input_boolean.study_aircon_power') == "on" %}
        auto
      {% else %}
        off
      {% endif %}

    set_hvac_mode:
      - action: script.set_hvac_mode
        data:
          aircon_deviceId: !secret study_aircon_deviceId
          aircon_hvac_mode: "{{ hvac_mode }}"
          aircon_state_sensor_entityId: sensor.study_aircon_state
          aircon_power_timer_entityId: timer.study_aircon_power

scripts.yaml:

set_hvac_mode:
  sequence:
    - action: rest_command.switchbot_irdevice_command
      data_template:
        deviceId: "{{ aircon_deviceId }}"
        command: >
          {% if aircon_hvac_mode == "auto" %}
            one touch
          {% else %}
            power off
          {% endif %}
        parameter: default
        commandType: customize
    - action: timer.start
      data_template:
        entity_id: "{{ aircon_power_timer_entityId }}"
    - delay: "00:00:20"
    - action: homeassistant.update_entity
      data_template:
        entity_id: "{{ aircon_state_sensor_entityId }}"

Edit:

  • confirm climate.study entity state does go to ‘auto’ when input_boolean.study_aircon_power is ‘on’
    → How can I test the rest_command? (In Developer Tools?)
    Developer Tools, call Action from RESTful Command as defined in configurations.yaml. Click on ‘YAML MODE’ to insert data for rest_command
    • rest_command can be successfully called here
  • confirm entire script.set_hvac_mode does run if called from Developer Tools
  • Just realised the climate template is a custom integration added from HACS ( GitHub - jcwillox/hass-template-climate: :snowflake:Templatable Climate Device for Home Assistant, Supports Running Actions On Service Calls.)
    → So the problem is related to template-climate From hvac_mode_template above, once input_boolean.study_aircon_power is ‘on’, why would set_hvac_mode script not run?
    → Adding a climate entity to Dashboard and setting the HVAC mode manually there to ‘auto’ does activate the script successfully. However climate.study state remains as ‘off’.
    → When input_boolean.study_aircon_power state is ‘on’, climate.study state does change to ‘auto’. However script doesn’t run.

Hi, have you updated HA in the meantime?

You could check:

  • if updated HA → the breaking changes between the version you were running and the one you run now
  • for know issues (link on SwitchBot Cloud - Home Assistant)

Other than that, I cannot help you but maybe someone else steps in who can.

I have, though no breaking changes as far as I can see (checking back to 2024.8 for Switchbot).

I do notice there was a YAML structure labelling change in 2024.10, which I have updated since but also understand shouldn’t affect the code functioning

Looks like the underlying problem is a problem with the template-climate integration. hvac_mode_template result is just not feeding into the climate entity as it should / did previously.

Have opened an issue on Github. Looks like there’s some sort of adjustment to new YAML structure?

Workaround for me here is to set up new automations to watch the change in input_boolean.study_aircon_power and then call the climate.set_hvac_mode service accordingly.

Hope this helps anyone with a similiar issue.