For an automation, I’m using a state trigger to detect when the target temperature of a thermostat changes. I would like to be able to detect which user triggered the change. To do this I’m trying to access trigger.context.user_id but the trigger does not contain any context.
I looked at many other posts and yes I’m triggering the automation through the entity and not from within the automation.
I logged the whole trigger and here’s what I get:
{‘id’: ‘0’, ‘idx’: ‘0’, ‘alias’: None, ‘platform’: ‘state’, ‘entity_id’: ‘climate.living_room_thermostat’, ‘from_state’: <state climate.living_room_thermostat=heat; hvac_modes=[<HVACMode.AUTO: ‘auto’>, <HVACMode.HEAT: ‘heat’>, <HVACMode.OFF: ‘off’>], min_temp=10, max_temp=24, preset_modes=[‘away’, ‘home’, ‘none’], current_temperature=20.9, temperature=21.0, hvac_action=heating, preset_mode=none, wattage=value=3195, occupancy=none, temp_display_status=on, temp_display_error=None, source_type=heating, early_start=off, setpoint_away=15, load_watt_1=3195, cycle_length=15, error_code=None, heat_level=60, pi_heating_demand=60, temp_display_value=21, second_display=exteriorTemperature, keypad=Locked, backlight=alwaysOn, time_format=24h, temperature_format=celsius, setpoint_max=24, setpoint_min=10, eco_status=off, eco_optOut=off, eco_setpoint=off, eco_power_relative=off, eco_power_absolute=off, eco_onOff=off, eco_setpoint_status=off, eco_setpoint_delta=0, hourly_kwh_count=5949.72, daily_kwh_count=5933.479, monthly_kwh_count=5889.035, hourly_kwh=1.555, daily_kwh=17.796, monthly_kwh=62.24, rssi=-53, sku=TH1124WF, device_model=1510, device_model_cfg=1, firmware=3.7.3, activation=True, id=198136, unit_of_measurement=°C, device_class=temperature, friendly_name=Living Room Themostat, supported_features=401 @ 2025-01-03T14:34:05.037682-05:00>, ‘to_state’: <state climate.living_room_thermostat=heat; hvac_modes=[<HVACMode.AUTO: ‘auto’>, <HVACMode.HEAT: ‘heat’>, <HVACMode.OFF: ‘off’>], min_temp=10, max_temp=24, preset_modes=[‘away’, ‘home’, ‘none’], current_temperature=20.9, temperature=21.5, hvac_action=heating, preset_mode=none, wattage=value=3195, occupancy=none, temp_display_status=on, temp_display_error=None, source_type=heating, early_start=off, setpoint_away=15, load_watt_1=3195, cycle_length=15, error_code=None, heat_level=60, pi_heating_demand=60, temp_display_value=21, second_display=exteriorTemperature, keypad=Locked, backlight=alwaysOn, time_format=24h, temperature_format=celsius, setpoint_max=24, setpoint_min=10, eco_status=off, eco_optOut=off, eco_setpoint=off, eco_power_relative=off, eco_power_absolute=off, eco_onOff=off, eco_setpoint_status=off, eco_setpoint_delta=0, hourly_kwh_count=5949.72, daily_kwh_count=5933.479, monthly_kwh_count=5889.035, hourly_kwh=1.555, daily_kwh=17.796, monthly_kwh=62.24, rssi=-53, sku=TH1124WF, device_model=1510, device_model_cfg=1, firmware=3.7.3, activation=True, id=198136, unit_of_measurement=°C, device_class=temperature, friendly_name=Living Room Themostat, supported_features=401 @ 2025-01-03T14:34:05.037682-05:00>, ‘for’: None, ‘attribute’: None, ‘description’: ‘state of climate.living_room_thermostat’}
I tried the same on a simple dimmer (both watching the state and the entity) and still get no context:
{‘id’: ‘0’, ‘idx’: ‘0’, ‘alias’: None, ‘platform’: ‘state’, ‘entity_id’: ‘light.front_foyer_chandelier’, ‘from_state’: <state light.front_foyer_chandelier=off; supported_color_modes=[<ColorMode.BRIGHTNESS: ‘brightness’>], color_mode=None, brightness=None, device_id=4, zone_id=3, friendly_name=Front Foyer Chandelier, supported_features=32 @ 2025-01-03T17:15:06.876633-05:00>, ‘to_state’: <state light.front_foyer_chandelier=on; supported_color_modes=[<ColorMode.BRIGHTNESS: ‘brightness’>], color_mode=brightness, brightness=255, device_id=4, zone_id=3, friendly_name=Front Foyer Chandelier, supported_features=32 @ 2025-01-04T15:01:04.165701-05:00>, ‘for’: None, ‘attribute’: None, ‘description’: ‘state of light.front_foyer_chandelier’}
Any idea why the context is not part of the trigger variable?
Thanks in advance!