首页 > 解决方案 > 如何让 Alexa 连续执行按钮“SetLight”指令?

问题描述

我正在努力让 Alexa 使用两个按钮显示闪烁模式,每个按钮显示一秒钟的橙色,每个按钮显示半秒钟的黑色缓冲区。所以模式将是:

我正在尝试堆叠它们,但它从来没有真正起作用。这是我正在使用的代码:

        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"
                        }
                    ]
                }]
            }
        });

我猜我的问题在于“无”触发事件相互抵消,但必须有办法做到这一点。有什么想法吗?

标签: alexaalexa-skills-kitamazon-echo

解决方案


我确实最终弄清楚了这一点,并想更新它以防其他人偶然发现它。

我试图在两个按钮上连续运行 4 个动画,但这是不可能的。每个按钮只能运行一个动画 (SetLight) 指令,因此在这种情况下,我最终使用了两个。一旦我改变了我的思维方式,我就可以制作两个动画,每个按钮一个对应的按钮亮一个,另一个是暗的。示例如下:

按钮 1 的 setLight 指令:

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
                }

按钮 2 的 setLight 指令:

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
                }

这就是基本的jist,希望它可以帮助别人。


推荐阅读