hass-template-climate
hass-template-climate copied to clipboard
Log Errors: Running script requires passing in a context // Thermostat: Already running
The problem
I am using climate_template to create virtual room thermostat along with a input_number that is the delta set temp between my room and my home (main) thermostat. For example, home is set at 20 degrees and bedroom at 19.5, delta is -0.5 in heating mode and +0.5 in cooling mode). I can then use that virtual thermostat to open/close Flair vents to control the temperature for each room.
My configuration seems to be working well but I do have log errors on startup and set_temperature that I'd like to understand and fix. Any help is appreciated here, I understand this is most probably a mistake on my side but I cannot figure it out. Thank you!
The log error on startup (on for each climate_template):
Logger: homeassistant.helpers.script.mock_room_thermostat
Source: helpers/script.py:1439
First occurred: 11:40:21 AM (1 occurrences)
Last logged: 11:40:21 AM
Mock Room Thermostat: Running script requires passing in a context
The error on set temperature:
Logger: homeassistant.helpers.script.mock_room_thermostat
Source: helpers/script.py:1453
First occurred: 11:45:38 AM (4 occurrences)
Last logged: 11:45:54 AM
Mock Room Thermostat: Already running
What version of Template Climate has the issue?
0.6.0
What version of Home Assistant are you running?
Home Assistant 2022.11.4 Supervisor 2022.11.2 Operating System 9.3 Frontend 20221108.0 - latest
What type of installation are you running?
Home Assistant OS
Example YAML snippet
input_number:
# +1 means +1 degree in heat mode and -1 degree in cool mode
mock_room_flair_temp_delta:
name: "Mock Room Temperature Delta"
min: -1.5
max: +1.5
step: .5
sensor:
- platform: template
sensors:
mock_room_flair_target_temperature:
unique_id: mock_room_flair_target_temperature
device_class: temperature
friendly_name: Mock Room target temperature
unit_of_measurement: '°C'
value_template: >
{% set mock_room_main_thermostat_temp = float(state_attr('climate.mock_main_thermostat', 'temperature'), -100) %}
{% set mock_room_flair_temp_delta_temp = float(states('input_number.mock_room_flair_temp_delta'), -100) %}
{% if mock_room_main_thermostat_temp == -100 or mock_room_flair_temp_delta_temp == -100 %}
{{ mock_room_main_thermostat_temp }}
{% else %}
{% if states('climate.mock_main_thermostat') == 'heat' %}
{{ mock_room_main_thermostat_temp + mock_room_flair_temp_delta_temp }}
{% elif states('climate.mock_main_thermostat') == 'cool' %}
{{ mock_room_main_thermostat_temp - mock_room_flair_temp_delta_temp }}
{% else %}
{{ mock_room_main_thermostat_temp }}
{% endif %}
{% endif %}
climate:
- platform: climate_template
unique_id: mock_room_thermostat
name: "Mock Room Thermostat"
modes:
# - "heat_cool"
- "heat"
- "cool"
- "off"
min_temp: 18
max_temp: 26
hvac_mode_template: "{{ states('climate.mock_main_thermostat') }}"
current_temperature_template: "{{ states('sensor.mock_room_flair_current_temperature') }}"
target_temperature_template: "{{ float(states('sensor.mock_room_flair_target_temperature'), -100) }}"
availability_template: "{{ 'heat' == states('climate.mock_main_thermostat') or 'cool' == states('climate.mock_main_thermostat') }}"
hvac_action_template: "{{ state_attr('climate.128_lansdbee', 'hvac_action') }}"
set_temperature:
- service: input_number.set_value
data:
value: >
{% set mock_room_main_thermostat_temp = float(state_attr('climate.mock_main_thermostat', 'temperature'), -100) %}
{% set mock_room_flair_temp_delta = float(states('input_number.mock_room_flair_temp_delta'), -100) %}
{% if mock_room_main_thermostat_temp == -100 or mock_room_main_thermostat_temp == -100 %}
{{ mock_room_flair_temp_delta }}
{% else %}
{% if 'heat' == states('climate.mock_main_thermostat') %}
{{ temperature - mock_room_main_thermostat_temp }}
{% elif 'cool' == states('climate.mock_main_thermostat') %}
{{ mock_room_main_thermostat_temp - temperature }}
{% else %}
{{ mock_room_flair_temp_delta }}
{% endif %}
{% endif %}
target:
entity_id: input_number.mock_room_flair_temp_delta
Anything in the logs that might be useful for us?
No response
Additional information
No response
Hi, Having same log warnings here also on all the climates (have 5 of them here). Although everything working fine, able to turn on/off, change modes, change temperature. No issues. Just those warnings in logs, during start up and during performing actions.
Anything can be done to avoid?
Hello,
if you like, you can use my forked repo, where I am merging multiple feature request with some of my own patches. ;-) The above error is patched there.
BTW: I probably know what is causing 'Already running' error, but please try first my latest release and report if the problem still exists. Thank you.
Hello,
regarding the 'Already running' error/warning. I need to know, if in your setup you:
- use both climate-template get template and set action for given setting (for example you use both
target_temperature_template
andset_temperature
orhvac_mode_template
andset_hvac_mode
) - running 'set' action will cause 'get' template to return updates value (this can be as you read from and write to same entity, or this is executed via chain of several entities updates).
This is to my knowledge the root cause issue, as with such setup if you change for example climate mode in HA GUI, then set_hvac_mode action is actually executed TWICE.
- first when you click in the GUI to change mode in climate card
- second time when hvac_mode_template updates entity hvac mode
I would propose not to run given set action based on get template change, as it doesn't seem to make sense at all.