Help with code tv lift

I am using this to raise and lower a tv lift, it is working as it should through app. When I use voice for Alexa by say Turn On Screen it carries out the command and operates the lift but then Alexa tells me that Screen is not responding. Is it looking for some type of feedback signal? Thanks Michael

#ifdef ENABLE_DEBUG
  #define DEBUG_ESP_PORT Serial
  #define NODEBUG_WEBSOCKETS
  #define NDEBUG
#endif 

#include <Arduino.h>
#if defined(ESP8266)
  #include <ESP8266WiFi.h>
#elif defined(ESP32) || defined(ARDUINO_ARCH_RP2040)
  #include <WiFi.h>
#endif

#include "SinricPro.h"
#include "SinricProSwitch.h"

#define WIFI_SSID         "SSID"
#define WIFI_PASS         "PASSWORD"
#define APP_KEY           "Appkey"
#define APP_SECRET        "Appsecret"

#define SWITCH_ID_1       "Switchid"
#define RELAY_1_PIN       16  // Relay 1 pin
#define RELAY_2_PIN       17  // Relay 2 pin

#define BAUD_RATE         115200

bool onPowerState1(const String &deviceId, bool &state) {
  Serial.printf("Device 1 turned %s\n", state ? "on" : "off");

  if (state) {
    // Turn ON relay 1 for 1000ms
    Serial.println("Relay 1 ON");
    digitalWrite(RELAY_1_PIN, HIGH);
    delay(1000);
    Serial.println("Relay 1 OFF");
    digitalWrite(RELAY_1_PIN, LOW);
  } else {
    // Turn ON relay 2 for 1000ms
    Serial.println("Relay 2 ON");
    digitalWrite(RELAY_2_PIN, HIGH);
    delay(1000);
    Serial.println("Relay 2 OFF");
    digitalWrite(RELAY_2_PIN, LOW);
  }

  return true;
}

void setupWiFi() {
  Serial.printf("\r\n[Wifi]: Connecting");

  #if defined(ESP8266)
    WiFi.setSleepMode(WIFI_NONE_SLEEP); 
    WiFi.setAutoReconnect(true);
  #elif defined(ESP32)
    WiFi.setSleep(false); 
    WiFi.setAutoReconnect(true);
  #endif

  WiFi.begin(WIFI_SSID, WIFI_PASS);

  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(250);
  }

  Serial.printf("connected!\r\n[WiFi]: IP-Address is %s\r\n", WiFi.localIP().toString().c_str());
}

void setupSinricPro() {
  pinMode(RELAY_1_PIN, OUTPUT);
  pinMode(RELAY_2_PIN, OUTPUT);
  digitalWrite(RELAY_1_PIN, LOW);
  digitalWrite(RELAY_2_PIN, LOW);

  SinricProSwitch& mySwitch1 = SinricPro[SWITCH_ID_1];
  mySwitch1.onPowerState(onPowerState1);

  SinricPro.onConnected([]() { Serial.println("Connected to SinricPro"); }); 
  SinricPro.onDisconnected([]() { Serial.println("Disconnected from SinricPro"); });

  SinricPro.begin(APP_KEY, APP_SECRET);
}

void setup() {
  Serial.begin(BAUD_RATE); Serial.println("\n\n");
  setupWiFi();
  setupSinricPro();
}

void loop() {
  SinricPro.handle();
}

Nowhere in this sketch is "screen not responding."

Explain your system and how it is used, including where you got this sketch, and all the sketches involved. This seems to be just a wifi interface to enable some relays.

Using this relay board to allow voice control of a motorized tv lift.

What voice control?

After it activates the relay and starts raising the tv, Amazon Alexa tells me it’s not responding even though it is working. Happens with raise and lower.

You leave a lot of information out. My next guess is verify your power is sufficient.

What info do you need, the board is running on a 28V dc power that is powering the linear actuator. Everything is working as it should but I just get the message that its not responding even though it is doing the command and starting the actuator. its just pulsing the relay for one second to switch the controller.

Ignore the message?

That is what I am doing now, but it would be nice if I didnt have to.

Did you check what I suggested?

If you are talking about power, yes.

Yes, I suspect insufficient power. This can cause a brown-out where comms might be dropped.

Steady 4.98 volts. Any other ideas?

Plenty.

I glanced at your code and noticed you do not report the success, which is why Alexa thinks she's failed.

I have no idea if this will work, but I fed the code and a query about what one is suppsoed to do to close the loop to a friend:

// untested. not human thinking:

Step-by-step fix:

First move the SinricProSwitch& mySwitch1 to a global scope. Place this above your onPowerState1() function.

SinricProSwitch& mySwitch1 = SinricPro[SWITCH_ID_1];

Then, inside `onPowerState1()`, add this line after the relay action:
mySwitch1.sendPowerStateEvent(state);

which I can't test, but it certainly looks plausible. The sendPowerStateEvent closes the loop with Alexa, it seems.

Try it. Report.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.