How do I match on new_state object properties in automation trigger

Home assistant logs the following event:

hass_1         | 2019-03-16 15:38:47 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.140275180964384] Sending 
{
  'id': 2,
  'type': 'event',
  'event': {
    'event_type': 'state_changed',
    'data': {
      'entity_id': 'sensor.cube_action',
      'old_state': <state sensor.cube_action=rotate_right; battery=100, voltage=3005, linkquality=81, action=rotate_right, angle=9.32, friendly_name=Cube action, icon=mdi:gesture-double-tap @ 2019-03-16T15:38:36.514704+03:00>,
      'new_state': <state sensor.cube_action=rotate_right; battery=100, voltage=3005, linkquality=76, action=rotate_right, angle=81.16, friendly_name=Cube action, icon=mdi:gesture-double-tap @ 2019-03-16T15:38:36.514704+03:00>
    },
    'origin': 'LOCAL',
    'time_fired': datetime.datetime(2019, 3, 16, 12, 38, 47, 445461, tzinfo=<UTC>),
    'context': {
      'id': '1c26012b43804f3391b6401b4f2ad6c0',
      'user_id': None
    }
  }
}

I want trigger to fire only when new state is rotate_right. I’ve tried

trigger:
  - platform: event
    event_type: state_changed
    event_data: 
      entity_id: sensor.cube_action
      new_state:
        cube_action: rotate_right

and

trigger:
  - platform: event
    event_type: state_changed
    event_data: 
      entity_id: sensor.cube_action
      new_state: { 'cube_action': 'rotate_right' }

But it doesn’t work (automation never triggers). If I remove new_state filter everything works but it matches other action events. new_state seems to be some kind of object, how to match on its properties correctly?

Perhaps, you could use state trigger with condition on the attribute.

That worked! Final code:

trigger:
  - platform: state
    entity_id: sensor.cube_action
condition:
  condition: template
  value_template: "{{ trigger.to_state.attributes.action in ['rotate_left', 'rotate_right'] }}"

You’re welcome