@123 you’ve done it again! Is there anything out of your knowledge Cheers.
btw,
On the topic of state machine, I have noticed that generic_thermostat component does not write its state and recover it on startup. Or at least that is what happens on my system. I can restart the core and all the temperature settings (i.e. setpoint) are lost. I get “unknown” as a value.
For those arriving here via search, this was the configuration.yaml to set the away_temp in my case as an automation but you get the idea and can adjust for your setup:
..
..
# Include python_script integration.
python_script:
..
..
automation:
# Copy current thermostat setpoint to 'away_temp' attribute
# to prevent changes when moving between 'away' and 'none' modes.
- alias: Thermostat setpoint to Away_Temp
initial_state: true
trigger:
platform: state
entity_id: climate.lounge
attribute: temperature
action:
service: python_script.set_state_or_attr
data_template:
entity_id: climate.lounge
away_temp: "{{ trigger.to_state.attributes.temperature }}"
..
..
Does the generic thermostat’ configuration contain the target_temp
option? On startup it should (at the very least) set it to that value. If that option isn’t present then I imagine it will default to unknown
until you set it to something (via the UI or a service call).
FWIW, Home Assistant periodically saves the state of a select few domains (and just prior to restart/shutdown) but definitely not all domains. This is from from an exhaustive list but just what comes to mind: input_boolean, automation, input_text, counter, etc. I don’t believe “climate” is one of them.
Indeed, target_temp is an attribute and this gets set to 18.0 in the yaml config. I’ve since started working on a python script (I ‘can do python’ for my sins) that reads the hass object and all state objects with attributes into a JSON and write this to a file which can be used on startup to (re)initialise my setup. There may well be native functionality in HA but I just haven’t found it. But as you say, there does seem to be some domains that are intrinsic to the state-machine but this is - again as you say - far from complete. I take it you meant “…far from an exhaustive list…”.
Hi @ninjaef, are you using a different python script that the one created by rodpayne ?
It seems that you are calling
service: python_script.set_state_or_attr
and rodpayne script is:
service: python_script.set_state
I’m trying to set away_temp using an input_number that is on my dashboard. So I can change the away temp.
Since my climate control system is both heater and cooler, during winter I do not want the same away temp than in summer !
So in order to avoid configuration change and server reboot every year, I would like to set that from an input number…
I have installed the python script from HACS: https://github.com/xannor/hass_py_set_state
And this is my automation so far:
##### Automations for handling thermostat modes and parameters
##### When input_select.thermostat_mode is changed, then thermostat hvac mode is changed as well
- id: updating_thermostat_when_thermostat_mode_changed
alias: Updating Thermostat when input "Thermostat Mode" is changed
trigger:
- platform: state
entity_id: input_select.thermostat_mode
condition:
- condition: state
entity_id: 'input_boolean.heating_override_switch'
state: 'off'
action:
- service: climate.set_hvac_mode
data:
entity_id: climate.thermostat_salon,climate.thermostat_chambres
hvac_mode: "{{ states('input_select.thermostat_mode') }}"
##### When changing the value of input_number.away_temp, then thermostat away_temp is changed as well
- id: updating_thermostat_when_away_temp_changed
alias: Updating Thermostat away_temp value when input "Temp Absent" is changed
trigger:
- platform: state
entity_id: input_number.away_temp
action:
- service: python_script.set_state
data_template:
entity_id: climate.thermostat_salon,climate.thermostat_chambres
away_temp: "{{ states('input_number.away_temp') }}"
“updating_thermostat_when_thermostat_mode_changed” is working just well,
but “updating_thermostat_when_away_temp_changed” using the python script is doing nothing.
It seems that it’s just working on a state, but trying to change “away_temp” here.
If you need anything that could help me, it would be cool
edit: If you have anything that could help me, it would be cool
…Sorry. I do not understand you … "if I need anything”
My setup is what it is - as per my previous post. It works as I require.
Sorry @ninjaef I meant “If you HAVE anything that could help me…”
What is the python script that you are using ?
I don’t see the function “set_state_or_attr” in rodpayne script.
Instead, there is the function “set_state” only. Maybe this is the reason why I cant’ update away_temp. Have you adapted rodpayne script in order to add “set attribute” capability to it?
I’m in the same situation than you here, I’m just trying to update away_temp dynamically and just can’t find a way to do it. Since you did it, i’m trying to understand how!
that is the filename in the CONFIG:python_scripts
directory, not a function.
inputEntity = data.get('entity_id')
if inputEntity is None:
logger.warning("===== entity_id is required if you want to set something.")
elif hass.states.get(inputEntity) is None:
logger.warning("===== unknown entity_id: %s", inputEntity)
else:
inputStateObject = hass.states.get(inputEntity)
logger.debug("inputStateObject = {0}".format(inputStateObject))
inputState = inputStateObject.state
logger.debug("inputState = {0}".format(inputState))
inputAttributesObject = inputStateObject.attributes.copy()
logger.debug("inputAttributesObject = {0}".format(inputAttributesObject))
# Loop all items from the 'data_template:' in config
for item in data:
logger.debug("LOOP: item = {0}".format(item))
# Get value
newAttribute = data.get(item)
logger.debug("LOOP: item = {0}; value = {1}".format(item,newAttribute))
if item == 'entity_id':
# Skip if config item is the entity name - we already have that
continue # already handled
elif item == 'state':
# If config item is 'state' then use the value
inputState = newAttribute
logger.debug("LOOP: inputState = {0}".format(inputState))
else:
# set the attribute to value
inputAttributesObject[item] = newAttribute
logger.debug("LOOP: inputAttributesObject[item] = {0}".format(newAttribute))
hass.states.set(inputEntity, inputState, inputAttributesObject)
copy that into a a file called set_state_or_attr.py
in your CONFIG:python_scripts
you need to restart HA
Thanks for your help, appreciated
no worries. is it working for you?
Nope. Not with your script or with rodpayne.
If renaming
service: python_script.set_state
to service: python_script.set_state_test (that does not exists…)
I do have an error in HA saying that it does not found the script. So that means it can find it when correctly named.
Now, I can’t find any log or information. I have tried to hard code a value, like this:
service: python_script.set_state_or_attr
data_template:
entity_id: climate.thermostat_salon
away_temp: 20
to see if it’s working, but nothing. The value of away mode is always the one initialized in the thermostat configuration: 18. It never changes.
I don’t know how to troubleshoot this…
Maybe it is related to the fact I’m using dual mode generic thermostat integration: ha-dualmodegeneric/custom_components/dualmode_generic/climate.py at 09455b0afc64950eebd575c361d787646e643d42 · zacs/ha-dualmodegeneric · GitHub I don’t know
No no no.
I cannot be any clearer,
the call you need to make is python_script.set_state_or_attr - why are you doing something else? No wonder it is not working. To be clear again, you must have the file set_state_or_attr.py in the in the subdirectory python_scripts within the homeassistant configuration directory (referenced as CONFIG:) above. If you do this it will work provided you make the correct call. Anything else and it will not work. You can test the service call in the Services tab from the Developer tools option on the front end.
Yes, this is what I do!
The call is working either with your script " set_state_or_attr" or with rodpayne’s “set_state”.
I have both files in my python_scripts folder.
Thank for the tips about Developer tools, I can see the service python_script.set_state_or_attr is here.
It does nothing when I call it…
Putting my thermostat in away mode right after:
Still at 18° …
Confused!
This indicated to me that it was not working…
Now you say it is working…
Sorry, I am too confused to help. I do not understand what you want - or - what is wrong.
Je ne sais pa !!
hahaha
Thanks for your help anyway
I was trying to call set_state_test, something that does not exist, just to confirm that I had an error showing in my logs, which I did have, so that meant the call was working and the script running when correctly called…!
The only thing I don’t know is why it’s not working ! There is no reason
Oh I see. You mean the automation works but the climate.salon entity attribute away_temp remains at 18? I have checked the dual mode generic component you are using and there is nothing in the code to cause this.
Post your homeassistant.log around 30 seconds either side of the automation run.
EDIT: Hang on!
Before posting the log, set the logger level to debug in your logger.yaml …
logger:
default: info #--ASSUMING this is what you have for other logs?
logs:
custom_components.dualmode_generic: debug
…then restart HA, then run the automation, then post the log.
And done!
Here is the log:
2021-02-09 16:29:51 INFO (MainThread) [custom_components.dualmode_generic.climate] Obtained current and target temperature. Generic Dual-mode thermostat active. 19.35, 19.5
2021-02-09 16:29:51 INFO (MainThread) [homeassistant.components.automation.heating_salon_when_enabling_timer_or_restoring_from_away_select_the_appropriate_temperature] Heating Salon when enabling timer or restoring from away select the appropriate temperature: Running automation actions
2021-02-09 16:29:51 INFO (MainThread) [homeassistant.components.automation.heating_salon_when_enabling_timer_or_restoring_from_away_select_the_appropriate_temperature] Heating Salon when enabling timer or restoring from away select the appropriate temperature: Choose at step 1: choice 2: Running automation actions
2021-02-09 16:29:51 INFO (MainThread) [homeassistant.components.automation.heating_salon_when_enabling_timer_or_restoring_from_away_select_the_appropriate_temperature] Heating Salon when enabling timer or restoring from away select the appropriate temperature: Choose at step 1: choice 2: Executing step call service
2021-02-09 16:30:00 INFO (MainThread) [homeassistant.components.automation.heating_salon_set_temp_weekday_evenings] Heating Salon set temp (weekday evenings): Running automation actions
2021-02-09 16:30:00 INFO (MainThread) [homeassistant.components.automation.heating_salon_set_temp_weekday_evenings] Heating Salon set temp (weekday evenings): Executing step call service
2021-02-09 16:30:00 INFO (MainThread) [homeassistant.components.automation.heating_chambres_set_temp_weekday_evenings] Heating Chambres set temp (weekday evenings): Running automation actions
2021-02-09 16:30:00 INFO (MainThread) [homeassistant.components.automation.heating_chambres_set_temp_weekday_evenings] Heating Chambres set temp (weekday evenings): Executing step call service
2021-02-09 16:30:00 INFO (MainThread) [custom_components.dualmode_generic.climate] Turning on heater switch.chauffage_chambres
2021-02-09 16:30:00 INFO (MainThread) [homeassistant.components.automation.heating_chambres_when_enabling_timer_or_restoring_from_away_select_the_appropriate_temperature] Heating Chambres when enabling timer or restoring from away select the appropriate temperature: Running automation actions
2021-02-09 16:30:00 INFO (MainThread) [homeassistant.components.automation.heating_chambres_when_enabling_timer_or_restoring_from_away_select_the_appropriate_temperature] Heating Chambres when enabling timer or restoring from away select the appropriate temperature: Choose at step 1: choice 3: Running automation actions
2021-02-09 16:30:00 INFO (MainThread) [homeassistant.components.automation.heating_chambres_when_enabling_timer_or_restoring_from_away_select_the_appropriate_temperature] Heating Chambres when enabling timer or restoring from away select the appropriate temperature: Choose at step 1: choice 3: Executing step call service
2021-02-09 16:30:00 INFO (MainThread) [homeassistant.helpers.script.chauffage_chambres] Chauffage Chambres: Running template script
2021-02-09 16:30:00 INFO (MainThread) [homeassistant.helpers.script.chauffage_chambres] Chauffage Chambres: Executing step call service
2021-02-09 16:30:00 INFO (MainThread) [custom_components.dualmode_generic.climate] Turning on heater switch.chauffage_chambres
2021-02-09 16:30:00 WARNING (MainThread) [homeassistant.helpers.script.chauffage_chambres] Chauffage Chambres: Already running
2021-02-09 16:30:00 INFO (MainThread) [homeassistant.helpers.script.chauffage_chambres] Chauffage Chambres: Executing step delay 0:00:30
2021-02-09 16:30:30 INFO (MainThread) [homeassistant.helpers.script.chauffage_chambres] Chauffage Chambres: Executing step call service
2021-02-09 16:38:33 INFO (MainThread) [homeassistant.components.automation.updating_thermostat_salon_away_temp_value_when_input_temp_absent_is_changed] Updating Thermostat Salon away_temp value when input "Temp Absent" is changed: Running automation actions
2021-02-09 16:38:33 INFO (MainThread) [homeassistant.components.automation.updating_thermostat_salon_away_temp_value_when_input_temp_absent_is_changed] Updating Thermostat Salon away_temp value when input "Temp Absent" is changed: Executing step call service
2021-02-09 16:38:33 INFO (MainThread) [homeassistant.components.automation.updating_thermostat_chambres_away_temp_value_when_input_temp_absent_is_changed] Updating Thermostat Chambres away_temp value when input "Temp Absent" is changed: Running automation actions
2021-02-09 16:38:33 INFO (MainThread) [homeassistant.components.automation.updating_thermostat_chambres_away_temp_value_when_input_temp_absent_is_changed] Updating Thermostat Chambres away_temp value when input "Temp Absent" is changed: Executing step call service
2021-02-09 16:38:33 INFO (SyncWorker_6) [homeassistant.components.python_script] Executing set_state.py: {'entity_id': 'climate.thermostat_salon', 'away_temp': 19.5}
2021-02-09 16:38:33 INFO (SyncWorker_13) [homeassistant.components.python_script] Executing set_state.py: {'entity_id': 'climate.thermostat_chambres', 'away_temp': 19.5}
Executing set_state.py: {‘entity_id’: ‘climate.thermostat_salon’, ‘away_temp’: 19.5}
Does looks good! I don’t get it
edit: Yes the entity_id is correct…