Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

@event_trigge state object #752

Answered by dbsdbs93
phsdv asked this question in Q&A
Discussion options

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
>
You must be logged in to vote

Replies: 1 comment 3 replies

Comment options

Doesn’t it get passed into your decorated handler as the event_type named argument?

You must be logged in to vote
3 replies
Comment options

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.

Comment options

Read this

Answer selected by phsdv
Comment options

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /