How to have Alexa perform button "SetLight" directives consecutively?

83 views Asked by At

I'm working on having Alexa display a pattern of blinks utilizing two buttons for a second of orange each with a half second of black buffer. So the pattern would be:

  • button 1 for 1 second of orange with half a second of black.

  • button 2 for one second of orange with half a second of black.

  • button 2 for one second of orange with half a second of black.

  • button 1 for one second of orange with half a second of black.

I'm trying to stack them, but it never really works. Here is the code I'm using:

        this.response._addDirective({
            "type": "GadgetController.SetLight",
            "version": 1,
            "targetGadgets": ["amzn1.ask.gadget.XXX1"],
            "parameters": {
                "triggerEvent": "none",
                "triggerEventTimeMs": 0,
                "animations": [{
                    "repeat": 1,
                    "targetLights": ["1"],
                    "sequence": [
                        {
                              "durationMs": 1000,
                              "blend": false,
                              "color": "000000"
                          },
                        {
                            "durationMs": 1000,
                            "blend": false,
                            "color": "b32d00"
                        }
                    ]
                }]
            }
        });
        this.response._addDirective({
            "type": "GadgetController.SetLight",
            "version": 1,
            "targetGadgets": ["amzn1.ask.gadget.XXXX2"],
            "parameters": {
                "triggerEvent": "none",
                "triggerEventTimeMs": 0,
                "animations": [{
                    "repeat": 1,
                    "targetLights": ["1"],
                    "sequence": [{
                            "durationMs": 1500,
                            "blend": false,
                            "color": "000000"
                        },
                        {
                            "durationMs": 1000,
                            "blend": false,
                            "color": "b32d00"
                        }
                    ]
                }]
            }
        });
        this.response._addDirective({
            "type": "GadgetController.SetLight",
            "version": 1,
            "targetGadgets": ["amzn1.ask.gadget.XXXX2"],
            "parameters": {
                "triggerEvent": "none",
                "triggerEventTimeMs": 0,
                "animations": [{
                    "repeat": 1,
                    "targetLights": ["1"],
                    "sequence": [
                        {
                              "durationMs": 2000,
                              "blend": false,
                              "color": "000000"
                          },
                        {
                            "durationMs": 1000,
                            "blend": false,
                            "color": "b32d00"
                        }
                    ]
                }]
            }
        });
        this.response._addDirective({
            "type": "GadgetController.SetLight",
            "version": 1,
            "targetGadgets": ["amzn1.ask.gadget.XXXX1"],
            "parameters": {
                "triggerEvent": "none",
                "triggerEventTimeMs": 0,
                "animations": [{
                    "repeat": 1,
                    "targetLights": ["1"],
                    "sequence": [
                        {
                              "durationMs": 2500,
                              "blend": false,
                              "color": "000000"
                          },
                        {
                            "durationMs": 1000,
                            "blend": false,
                            "color": "b32d00"
                        }
                    ]
                }]
            }
        });

I'm guessing my issue lies around the "none" trigger events cancelling each other out, but there has to be a way to do it. Any thoughts?

1

There are 1 answers

0
Daniel Costello On

I did end up figuring this out and wanted to update this in case someone else stumbles across it.

I was trying to run 4 animations consecutively running over two buttons, but this isn't possible. You can only have one animation (SetLight) directive running per button, so this this case I ended up using two. Once I changed my way of thinking to this, I was able to have two animations, one for each button which had the proper button light up one the other one was dark. Examples are below:

Button 1's setLight directive:

this.response._addDirective({
                "type": "GadgetController.SetLight",
                "version": 1,
                "targetGadgets": [`${deviceIds[0]}`],
                "parameters": {
                    "animations": [{
                        "repeat": 1,
                        "targetLights": ["1"],
                        "sequence": [{
                                "durationMs": 3000,
                                "blend": false,
                                "color": "000000"
                            },
                            {
                                "durationMs": 1000,
                                "blend": false,
                                "color": b32d00
                            },
                            {
                                "durationMs": 500,
                                "blend": false,
                                "color": "000000"
                            },
                            {
                                "durationMs": 1000,
                                "blend": false,
                                "color": 000000
                            },
                            {
                                "durationMs": 500,
                                "blend": false,
                                "color": "000000"
                            }
                        ]
                    }],
                    "triggerEvent": "none",
                    "triggerEventTimeMs": 0
                }

Button 2's setLight directive:

this.response._addDirective({
                "type": "GadgetController.SetLight",
                "version": 1,
                "targetGadgets": [`${deviceIds[0]}`],
                "parameters": {
                    "animations": [{
                        "repeat": 1,
                        "targetLights": ["1"],
                        "sequence": [{
                                "durationMs": 3000,
                                "blend": false,
                                "color": "000000"
                            },
                            {
                                "durationMs": 1000,
                                "blend": false,
                                "color": 000000
                            },
                            {
                                "durationMs": 500,
                                "blend": false,
                                "color": "000000"
                            },
                            {
                                "durationMs": 1000,
                                "blend": false,
                                "color": b32d00
                            },
                            {
                                "durationMs": 500,
                                "blend": false,
                                "color": "000000"
                            },
                            {
                                "durationMs": 10000,
                                "blend": false,
                                "color": "b32d00"
                            }
                        ]
                    }],
                    "triggerEvent": "none",
                    "triggerEventTimeMs": 0
                }

Thats the basic jist, hope it helps someone else.