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:
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.