-
Notifications
You must be signed in to change notification settings - Fork 58
-
I have a Shelly plus i4, and pressing a button will generate an event that I can catch with event_trigger. I get an old_state and an new_state. An example output of a new_state is shown below.
My question is how do I get the value of event_type?
@event_trigger(EVENT_STATE_CHANGED, "entity_id.startswith('event.shellyplusi4_slaapkamer')")
def test333ttt(entity_id=None, event_type=None, old_state=None, new_state=None):
log.warning(f"Shelly: {new_state=}")
new_state= <
state event.shellyplusi4_slaapkamer_input_0=2025年08月25日T18:29:11.485+00:00;
event_types=['double_push', 'triple_push', 'long_push', 'btn_down', 'btn_up', 'single_push'],
event_type=btn_down,
device_class=button,
friendly_name=shellyplusi4-slaapkamer Input 0 @ 2025年08月25日T20:29:11.485637+02:00
>
Beta Was this translation helpful? Give feedback.
All reactions
Read this
Replies: 1 comment 3 replies
-
Doesn’t it get passed into your decorated handler as the event_type
named argument?
Beta Was this translation helpful? Give feedback.
All reactions
-
event_type gets passed also. When I look at all arguments using **kwargs, I see it, but it is not useful:
kwargs={
'trigger_type': 'event',
'event_type': 'state_changed',
'context': <homeassistant.core.Context object at 0x7f671576a840>,
'old_state': <state event.shellyplusi4_slaapkamer_input_1=2025年08月25日T18:41:42.437+00:00; event_types=['double_push', 'triple_push', 'long_push', 'btn_down', 'btn_up', 'single_push'], event_type=btn_up, device_class=button, friendly_name=shellyplusi4-slaapkamer Input 1 @ 2025年08月25日T20:41:42.437367+02:00>,
'new_state': <state event.shellyplusi4_slaapkamer_input_1=2025年08月25日T18:41:43.438+00:00; event_types=['double_push', 'triple_push', 'long_push', 'btn_down', 'btn_up', 'single_push'], event_type=double_push, device_class=button, friendly_name=shellyplusi4-slaapkamer Input 1 @ 2025年08月25日T20:41:43.439085+02:00>}
event_type only tells me that the state has changed, not which one.
Beta Was this translation helpful? Give feedback.
All reactions
-
Read this
Beta Was this translation helpful? Give feedback.
All reactions
-
Yes, thank you, thats the pointer I needed! I can get the event type like this:new_state.attributes['event_type']
After pressing and releasing a button I get this:
new_state.attributes['event_type']=btn_down
new_state.attributes['event_type']=btn_up
new_state.attributes['event_type']=single_push
Beta Was this translation helpful? Give feedback.