Python script for light timer with blackout (attribute not set)

I’m trying to write a python_script service which will allow a light time to have blackouts.

To set up the actual times for this I am using the automation:

    - id: shower_timer_id
      alias: Shower Timer
      trigger:
      - entity_id: switch.master_shower_switch
        for:
          seconds: 60
        from: 'off'
        platform: state
        to: 'on'
      - entity_id: switch.master_shower_switch
        for:
          seconds: 5
        from: 'on'
        platform: state
        to: 'off'
      action:
      - alias: tell me
        data:
          message: shower message
        service: notify.ios_devansiphone7
      - data:
          entity_id: switch.master_shower_switch
        service: python_script.timed_off

The idea being, when we are off for less than 5 seconds, we will be in a “blackout” window the next time we turn on which will prevent the timer from turning off the light.

The actual script is as follows:

    entity_id  = data.get('entity_id')
    states = hass.states.get(entity_id)
    atts = states.attributes.copy()

    if states.state == "off":
      hass.services.call('notify', 'ios_devansiphone7', {'message': 'blackout disabled', 'title':'timed_off'})
      logger.info('Cleared Blackout for ' + str(entity_id))
      atts['blackout'] = False
      hass.states.set(entity_id, states.state, atts)
    else:
      if states.attributes.get('blackout') == False:
        hass.services.call('notify', 'ios_devansiphone7', {'message': 'Turning off shower', 'title':'timed_off'})
        logger.info('Tuning off ' + str(entity_id))
        atts['blackout'] = True
        hass.states.set(entity_id, states.state, atts)
        data = { "entity_id" : entity_id }
        hass.services.call('light', 'turn_off', data)
      else:
        hass.services.call('notify', 'ios_devansiphone7', {'message': 'blackout observed', 'title':'timed_off'})
        logger.info('Timer disabled on blackout')

Eventually I think this ends up sending me a notification that the light is on and allowing me to take action based on response but here was a the rough cut to test the idea. The problem that I’m seeing right now is that the “blackout” attribute never appears to be set on the switch. I’m not very confident that I can even create arbitrary attributes for an entity so I was hoping for that clarification first, can anyone confirm?

Thanks,
Devan