Hello!
I have a generic thermostat hooked up to a switch and thermostat in each room. I would like the button on the thermostat to turn off/on the generic thermostat. However, I also want to be able to control the thermostat from my phone.
Ideally, I would be able to find out what changed the state of the switch, check if it was done with a manual change to the switch, and then update the climate entity. In the Lovelace UI, it tells exactly what triggered the change, so I assumed this was possible.
However, the context of the trigger doesn’t provide the platform that triggered the change. I did search around the forums and found a bunch of people talking about the using the user_id
of the context to determine if it was done by manual change or not. However, changes in Homekit also register with no user_id
. So I wouldn’t be able to determine if HomeKit switched it off or a manual button press.
Here is an example of the trigger context from a switch done via the climate entity in the lovelace ui:
variables:
trigger:
id: "0"
idx: "0"
alias: null
platform: state
entity_id: switch.office_heater_switch
from_state:
entity_id: switch.office_heater_switch
state: "on"
attributes:
friendly_name: Office Heater Switch
last_changed: "2022-12-20T17:03:43.256959+00:00"
last_updated: "2022-12-20T17:03:43.256959+00:00"
context:
id: 01GMR7VDMRC0T8HS8WZN8N2SW0
parent_id: null
user_id: null
to_state:
entity_id: switch.office_heater_switch
state: "off"
attributes:
friendly_name: Office Heater Switch
last_changed: "2022-12-20T17:04:39.300917+00:00"
last_updated: "2022-12-20T17:04:39.300917+00:00"
context:
id: 01GMR7X495NVMZK3SZBZ39GHQV
parent_id: null
user_id: <REDACTED>
for: null
attribute: null
description: state of switch.office_heater_switch
context:
id: 01GMR7X495NVMZK3SZBZ39GHQV
parent_id: null
user_id: <REDACTED>
And here is what it looks like if triggered by homekit or with a manual button press:
variables:
trigger:
id: "0"
idx: "0"
alias: null
platform: state
entity_id: switch.office_heater_switch
from_state:
entity_id: switch.office_heater_switch
state: "off"
attributes:
friendly_name: Office Heater Switch
last_changed: "2022-12-20T17:04:39.300917+00:00"
last_updated: "2022-12-20T17:04:39.300917+00:00"
context:
id: 01GMR7X495NVMZK3SZBZ39GHQV
parent_id: null
user_id: 376150e426224c31926af03641ae2490
to_state:
entity_id: switch.office_heater_switch
state: "on"
attributes:
friendly_name: Office Heater Switch
last_changed: "2022-12-20T17:05:14.385719+00:00"
last_updated: "2022-12-20T17:05:14.385719+00:00"
context:
id: 01GMR7Y6MHS6KQ5WFFRRWYMEGX
parent_id: null
user_id: null
for: null
attribute: null
description: state of switch.office_heater_switch
context:
id: 01GMR7Y6MHS6KQ5WFFRRWYMEGX
parent_id: null
user_id: null
The User ID is “null” in both situations so I can’t use that.
I was hoping someone might have an idea.
Also, why would the context not contain the platform that triggered it if Home Assistant is already gathering that information?