Webthing-python documentation of actions as examples

Let’s start a list of code examples of actions.
If you have an example of actions you wrote and give me a link or a snippet I will add it to documentation.

I made an action that exposes a linear fade over time.
https://github.com/novski/webthing-pwm/blob/master/pwm-thing.py
L27:

class FadeLedStrip(Action):

    def __init__(self, thing, input_):
        Action.__init__(self, uuid.uuid4().hex, thing, 'fade', input_=input_)

    def perform_action(self):
        brightness_after = self.input['brightness']
        brightness_now = self.thing.get_property('brightness')
        if  brightness_after > brightness_now :
            percentage = brightness_after - brightness_now
            delay_ms = self.input['duration'] / percentage
            logging.debug('FadeLedStrip.perform_action: start incrementing, brightness now %s, brightness afer %s, percentage %s, delay_ms %s, duration %s',
                         brightness_now,
                         brightness_after,
                         percentage,
                         delay_ms,
                         self.input['duration'])
            while brightness_after > self.thing.get_property('brightness'):
                self.thing.set_property('brightness', 
                                        self.thing.get_property('brightness')+1)
                time.sleep(delay_ms / 1000)
            logging.debug('finished incrementing')
        elif brightness_after < brightness_now:
            percentage = brightness_now - brightness_after
            delay_ms = self.input['duration'] / percentage
            logging.debug('start decrementing, brightness now %s, brightness afer %s, percentage %s, delay_ms %s, duration %s',
                        brightness_now,
                        brightness_after,
                        percentage,delay_ms,
                        self.input['duration'])
            while brightness_after < self.thing.get_property('brightness'):
                self.thing.set_property('brightness', 
                                        self.thing.get_property('brightness')-1)
                time.sleep(delay_ms / 1000)
            logging.debug('FadeLedStrip.perform_action: finished decrementing')
        return

and its propterty on L109:

        self.add_available_action('fade',
        {
            'title': 'Fade',
            'description': 'Fade the lamp to a given level',
            'input': {
                'type': 'object',
                'required': [
                    'brightness',
                    'duration',
                ],
                'properties': {
                    'brightness': {
                        'type': 'integer',
                        'minimum': 0,
                        'maximum': 100,
                        'unit': 'percent',
                    },
                    'duration': {
                        'type': 'integer',
                        'minimum': 1,
                        'unit': 'milliseconds',
                    },
                },
            },
        },
        FadeLedStrip)