[Solved] Obtaining a value from a GE 12730 Fan Control Switch event's JSON data

I’m creating an automation to detect when my GE 12730 Fan Control Switch changes speeds. What I need to obtain is the value after speed= in new_state below.

I’ve tried trigger.event.data.new_state.speed and trigger.event.data.new_state.attributes.speed but neither seems to return the value, high in this instance. Can anyone explain how to reference this value? This is the JSON output from the event in the log:

{
  'id': 2,
  'type': 'event',
  'event': {
    'event_type': 'state_changed',
    'data': {
      'entity_id': 'fan.bedroom_fan_level',
      'old_state': <state fan.bedroom_fan_level=on;speed=low,
      speed_list=[
        'off',
        'low',
        'medium',
        'high'
      ],
      node_id=24,
      value_index=0,
      value_instance=1,
      value_id=72057594455398017,
      friendly_name=GE12730FanControlSwitchLevel,
      supported_features=1@2019-02-26T22: 37: 00.580246-06: 00>,
      'new_state': <state fan.bedroom_fan_level=on;speed=high,
      speed_list=[
        'off',
        'low',
        'medium',
        'high'
      ],
      node_id=24,
      value_index=0,
      value_instance=1,
      value_id=72057594455398017,
      friendly_name=GE12730FanControlSwitchLevel,
      supported_features=1@2019-02-26T22: 37: 00.580246-06: 00>
    },
    'origin': 'LOCAL',
    'time_fired': datetime.datetime(2019,
    2,
    27,
    4,
    37,
    12,
    219574,
    tzinfo=<UTC>),
    'context': {
      'id': 'a3adff3d36694145a174dfb54ebdc28e',
      'user_id': None
    }
  }
}

I’m not sure if this is the “best” way to do it, but this is what worked.

trigger.event.data.new_state.attributes.speed is what I was looking for.

I’m also including the system_log.write code that allowed me to see the values of the variables in the log file.

This automation updates an input_select based upon the speed that is selected via the zwave switch itself.

##################################################################
- alias: bedroom fan speed by zwave switch
##################################################################
  initial_state: true
  trigger:
    platform: event
    event_type: state_changed
    event_data:
      entity_id: fan.bedroom_fan_level
  action:
    - service: system_log.write
      data_template:
        message: "### Speed is: {{ trigger.event.data.new_state.attributes.speed | title }}"
        level: info
        logger: my_debug
    - service: input_select.select_option
      entity_id: input_select.bedroom_fan_speed
      data_template:
        option: '{{ trigger.event.data.new_state.attributes.speed | title }}'