add 9 further alexa devices for calling presets 1-9

This commit is contained in:
siggel 2022-02-02 21:46:19 +01:00
parent 795c515999
commit 3d378211b6
4 changed files with 56 additions and 13 deletions

View File

@ -12,7 +12,7 @@
; default_envs = travis_esp8266, travis_esp32
# Release binaries
default_envs = nodemcuv2, esp8266_2m, esp01_1m_full, esp32dev, esp32_eth, esp32s2_saola, esp32c3
; default_envs = nodemcuv2, esp8266_2m, esp01_1m_full, esp32dev, esp32_eth, esp32s2_saola, esp32c3
# Build everything
; default_envs = esp32dev, esp8285_4CH_MagicHome, codm-controller-0.6-rev2, codm-controller-0.6, esp32s2_saola, d1_mini_5CH_Shojo_PCB, d1_mini, sp501e, travis_esp8266, travis_esp32, nodemcuv2, esp32_eth, anavi_miracle_controller, esp07, esp01_1m_full, m5atom, h803wf, d1_mini_ota, heltec_wifi_kit_8, esp8285_H801, d1_mini_debug, wemos_shield_esp32, elekstube_ips
@ -23,7 +23,7 @@ default_envs = nodemcuv2, esp8266_2m, esp01_1m_full, esp32dev, esp32_eth, esp32s
; default_envs = esp8266_2m
; default_envs = esp01_1m_full
; default_envs = esp07
; default_envs = d1_mini
default_envs = d1_mini
; default_envs = heltec_wifi_kit_8
; default_envs = h803wf
; default_envs = d1_mini_debug

View File

@ -16,13 +16,32 @@ void alexaInit()
{
if (alexaEnabled && WLED_CONNECTED)
{
if (espalexaDevice == nullptr) //only init once
if (espalexa.getDeviceCount() == 0) //only init once
{
// the original configured device for keeping old behavior
espalexaDevice = new EspalexaDevice(alexaInvocationName, onAlexaChange, EspalexaDeviceType::extendedcolor);
espalexa.addDevice(espalexaDevice);
// 9 further devices with names Effect 1-9 (in German) for switching presets 1-9 on (off and other commands will work like before)
// switch on e.g. by saying (in German): "Alexa, Effekt eins anschalten"
espalexaDevice = new EspalexaDevice("Effekt eins", onAlexaChange, EspalexaDeviceType::extendedcolor);
espalexa.addDevice(espalexaDevice);
espalexaDevice = new EspalexaDevice("Effekt zwei", onAlexaChange, EspalexaDeviceType::extendedcolor);
espalexa.addDevice(espalexaDevice);
espalexaDevice = new EspalexaDevice("Effekt drei", onAlexaChange, EspalexaDeviceType::extendedcolor);
espalexa.addDevice(espalexaDevice);
espalexaDevice = new EspalexaDevice("Effekt vier", onAlexaChange, EspalexaDeviceType::extendedcolor);
espalexa.addDevice(espalexaDevice);
espalexaDevice = new EspalexaDevice("Effekt fünf", onAlexaChange, EspalexaDeviceType::extendedcolor);
espalexa.addDevice(espalexaDevice);
espalexaDevice = new EspalexaDevice("Effekt sechs", onAlexaChange, EspalexaDeviceType::extendedcolor);
espalexa.addDevice(espalexaDevice);
espalexaDevice = new EspalexaDevice("Effekt sieben", onAlexaChange, EspalexaDeviceType::extendedcolor);
espalexa.addDevice(espalexaDevice);
espalexaDevice = new EspalexaDevice("Effekt acht", onAlexaChange, EspalexaDeviceType::extendedcolor);
espalexa.addDevice(espalexaDevice);
espalexaDevice = new EspalexaDevice("Effekt neun", onAlexaChange, EspalexaDeviceType::extendedcolor);
espalexa.addDevice(espalexaDevice);
espalexa.begin(&server);
} else {
espalexaDevice->setName(alexaInvocationName);
}
}
}
@ -35,10 +54,15 @@ void handleAlexa()
void onAlexaChange(EspalexaDevice* dev)
{
espalexaDevice = dev;
EspalexaDeviceProperty m = espalexaDevice->getLastChangedProperty();
String name = espalexaDevice->getName();
if (m == EspalexaDeviceProperty::on)
{
if (name == alexaInvocationName)
{
// keep the old switch-on behavior for the configured name
if (!macroAlexaOn)
{
if (bri == 0)
@ -50,6 +74,20 @@ void onAlexaChange(EspalexaDevice* dev)
applyPreset(macroAlexaOn, CALL_MODE_ALEXA);
if (bri == 0) espalexaDevice->setValue(briLast); //stop Alexa from complaining if macroAlexaOn does not actually turn on
}
} else {
// new switch-on behavior for devices 1-9 which switch on presets 1-9
byte preset = 0;
if (name == "Effekt eins") preset = 1;
else if (name == "Effekt zwei") preset = 2;
else if (name == "Effekt drei") preset = 3;
else if (name == "Effekt vier") preset = 4;
else if (name == "Effekt fünf") preset = 5;
else if (name == "Effekt sechs") preset = 6;
else if (name == "Effekt sieben") preset = 7;
else if (name == "Effekt acht") preset = 8;
else if (name == "Effekt neun") preset = 9;
applyPreset(preset,CALL_MODE_ALEXA);
}
} else if (m == EspalexaDeviceProperty::off)
{
if (!macroAlexaOff)

View File

@ -359,6 +359,11 @@ public:
return false;
}
// get device count
uint8_t getDeviceCount() {
return currentDeviceCount;
}
//service loop
void loop() {
#ifndef ESPALEXA_ASYNC

View File

@ -103,7 +103,7 @@
#ifndef WLED_DISABLE_ALEXA
#define ESPALEXA_ASYNC
#define ESPALEXA_NO_SUBPAGE
#define ESPALEXA_MAXDEVICES 1
#define ESPALEXA_MAXDEVICES 10
// #define ESPALEXA_DEBUG
#include "src/dependencies/espalexa/Espalexa.h"
#endif