Closed cfinch100 closed 5 days ago
Can you please express your question in understandable sentences? I'm afraid I can't follow you.
the code waters the garden in 2 seperate steps relay1 is on for 10mins when that has stopped relay2 starts for same time then both are off until next watering which for teating is 1 hr,esp32 sends watering to bserial which is right,eg relay1 on/off,relay2 on/off but the app shows different values relay on ,on app says off, if i press zone1 on app somtimes it changes sometimes not but if serial says relay1 is off the app says its on,when i set app up it would send notification sound now it does not and mostly times out ,wifi is fine but tried to change/update on app and it just buffered colin
entered wifi address in browser and logged on and could change relays no problem with the buttons colin
Ah, now I got it.
Your notifyPhone
function does not send any notifications but just serial pints.
You have to send events when your relays are controlled outside of SinricPro, like from timed events.
Please see sendPowerStateEvent
but why if i try to change relay with phone to off on serial it sayson colin
?
does the code look ok ,and is it a sinric problem colin
Sorry, but I don't understand.
Do you use SinricPro App to control your device?
yes use sinric to override program colin
Please try with the official switch example
eg:
SinricProSwitch& mySwitch1 = SinricPro[SWITCH_ID_RELAY1];
bool success = mySwitch1.sendPowerStateEvent(myPowerState);
You should be able to do the same via Automation without writing any logic..
I'll give it a go today not promising will do it thoughColin
Sent from Sky Yahoo Mail on Android
On Thu, Jun 13, 2024 at 3:50, Aruna @.***> wrote:
Seems your issue is you are turning on/off the relay but not letting the server know the new state. You can use sendPowerStateEvent to do that.
eg: SinricProSwitch& mySwitch1 = SinricPro[SWITCH_ID_RELAY1]; bool success = mySwitch1.sendPowerStateEvent(myPowerState);
You should be able to do the same via an Automation without writing any logic..
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
HiHave done code as in email but comes up with myPowerState was not declared in scope I'm bit new to all this so any guidance would be appreciated Regards colin
Sent from Sky Yahoo Mail on Android
On Thu, Jun 13, 2024 at 3:50, Aruna @.***> wrote:
Seems your issue is you are turning on/off the relay but not letting the server know the new state. You can use sendPowerStateEvent to do that.
eg: SinricProSwitch& mySwitch1 = SinricPro[SWITCH_ID_RELAY1]; bool success = mySwitch1.sendPowerStateEvent(myPowerState);
You should be able to do the same via an Automation without writing any logic..
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
Hi now says can't set statepower and no buttons work on appColin
Sent from Sky Yahoo Mail on Android
On Thu, Jun 13, 2024 at 8:00, @.**@.> wrote: HiHave done code as in email but comes up with myPowerState was not declared in scope I'm bit new to all this so any guidance would be appreciated Regards colin
Sent from Sky Yahoo Mail on Android
Not sure if this helps on the app on phone I can turn zone2 off and on but when you turn on zone1 it turns zone2 off although the data on button is wrong g ie button1 says on although it's off on serialRegards colin
Sent from Sky Yahoo Mail on Android
On Thu, Jun 13, 2024 at 8:44, @.**@.> wrote: Hi now says can't set statepower and no buttons work on appColin
Sent from Sky Yahoo Mail on Android
On Thu, Jun 13, 2024 at 8:00, @.**@.> wrote: HiHave done code as in email but comes up with myPowerState was not declared in scope I'm bit new to all this so any guidance would be appreciated Regards colin
Sent from Sky Yahoo Mail on Android
Check the code marked as / CHANGED: Update server with new status / for example how to update the server
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
#include <SinricPro.h>
#include <SinricProSwitch.h>
// Define the pins
#define RELAY1_PIN 5
#define RELAY2_PIN 18
#define BUTTON_PIN 13
// WiFi and Server
AsyncWebServer server(80);
// Watering schedule (in milliseconds)
const unsigned long interval = 1 * 60 * 60 * 1000; // 6 hours (4 times a day)changed to1
const unsigned long relayOnDuration = 10 * 60 * 1000; // 10 minutes
// Timers
unsigned long previousMillis = 0;
unsigned long relay1StartMillis = 0;
unsigned long relay2StartMillis = 0;
// Watering state
bool relay1On = false;
bool relay2On = false;
// Watering times
unsigned long lastWateringStartTime = 0;
unsigned long nextWateringStartTime = interval;
// SinricPro
#define APP_KEY "xxxx" // Should look like "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
#define APP_SECRET "xxx" // Should look like "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
#define SWITCH_ID_RELAY1 "xxxx" // Should look like "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
#define SWITCH_ID_RELAY2 "xxx" // Should66658d26888aa7f7a235bd51 look like "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
// Function prototypes
void setupWifi();
void handleButtonPress();
void notifyPhone(bool state);
void startWateringCycle(int relayNum);
bool onPowerState1(const String &deviceId, bool &state);
bool onPowerState2(const String &deviceId, bool &state);
void setupSinricPro();
void setup() {
Serial.begin(115200);
pinMode(RELAY1_PIN, OUTPUT);
pinMode(RELAY2_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
digitalWrite(RELAY1_PIN, LOW);
digitalWrite(RELAY2_PIN, LOW);
setupWifi();
// Button press interrupt
attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), handleButtonPress, FALLING);
server.begin();
setupSinricPro();
Serial.println("Setup complete");
}
void loop() {
unsigned long currentMillis = millis();
SinricPro.handle();
// Check if it's time to start a new watering cycle
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
startWateringCycle(1); // Start watering cycle for relay 1
Serial.println("Watering cycle for relay 1 started");
}
// Check if relay1 should turn off and relay2 should turn on
if (relay1On && (currentMillis - relay1StartMillis >= relayOnDuration)) {
digitalWrite(RELAY1_PIN, LOW);
relay1On = false;
relay2StartMillis = currentMillis;//delay
digitalWrite(RELAY2_PIN, HIGH);
relay2On = true;
/* CHANGED: Update server with new status */
SinricProSwitch& mySwitch1 = SinricPro[SWITCH_ID_RELAY1];
mySwitch1.sendPowerStateEvent(false);
SinricProSwitch& mySwitch2 = SinricPro[SWITCH_ID_RELAY2];
mySwitch2.sendPowerStateEvent(true);
notifyPhone(true); // Notification for relay 2 on
Serial.println("Relay 1 turned off, Relay 2 turned on");
}
// Check if relay2 should turn off
if (relay2On && (currentMillis - relay2StartMillis >= relayOnDuration)) {
digitalWrite(RELAY2_PIN, LOW);
/* CHANGED: Update server with new status */
SinricProSwitch& mySwitch2 = SinricPro[SWITCH_ID_RELAY2];
mySwitch2.sendPowerStateEvent(false);
relay2On = false;
notifyPhone(false); // Notification for relay 2 off
Serial.println("Relay 2 turned off");
}
}
// Start the watering cycle for the specified relay
void startWateringCycle(int relayNum) {
if (relayNum == 1) {
relay1StartMillis = millis();
digitalWrite(RELAY1_PIN, HIGH);
relay1On = true;
notifyPhone(true); // Notification for relay 1 on
} else if (relayNum == 2) {
relay2StartMillis = millis();
digitalWrite(RELAY2_PIN, HIGH);
relay2On = true;
notifyPhone(true); // Notification for relay 2 on
}
}
// Handle button press for manual override
void handleButtonPress() {
if (relay1On || relay2On) {
digitalWrite(RELAY1_PIN, LOW);
digitalWrite(RELAY2_PIN, LOW);
relay1On = false;
relay2On = false;
notifyPhone(false);
/* CHANGED: Update server with new status */
SinricProSwitch& mySwitch1 = SinricPro[SWITCH_ID_RELAY1];
mySwitch1.sendPowerStateEvent(false);
SinricProSwitch& mySwitch2 = SinricPro[SWITCH_ID_RELAY2];
mySwitch2.sendPowerStateEvent(false);
Serial.println("Watering cycle stopped");
} else {
startWateringCycle(1); // Start watering cycle for relay 1
Serial.println("Manual watering cycle for relay 1 started");
}
}
// Notify phone via a simple web server message (simplified)
void notifyPhone(bool state) {
// Implement your notification logic here (e.g., HTTP request to a notification service)
Serial.print("Notification: ");
Serial.println(state ? "ON" : "OFF");
}
// Setup Wi-Fi
void setupWifi() {
Serial.println("Connecting to WiFi...");
WiFi.begin("xxx", "xxx");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println();
Serial.print("Connected to WiFi. IP address: ");
Serial.println(WiFi.localIP());
// Set up a simple web server to display the status
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
String response = "Relay 1: " + String(relay1On ? "ON" : "OFF") + "<br>";
response += "Relay 2: " + String(relay2On ? "ON" : "OFF") + "<br>";
response += "Last Watering: " + String(lastWateringStartTime) + "<br>";
response += "Next Watering: " + String(nextWateringStartTime);
request->send(200, "text/html", response);
});
}
// Setup SinricPro
void setupSinricPro() {
SinricProSwitch& mySwitch1 = SinricPro[SWITCH_ID_RELAY1];
mySwitch1.onPowerState(onPowerState1);
SinricProSwitch& mySwitch2 = SinricPro[SWITCH_ID_RELAY2];
mySwitch2.onPowerState(onPowerState2);
SinricPro.begin(APP_KEY, APP_SECRET);
}
// Alexa Power State Callback for Relay 1
bool onPowerState1(const String &deviceId, bool &state) {
if (state) {
startWateringCycle(1); // Start watering cycle for relay 1
} else {
digitalWrite(RELAY1_PIN, LOW);
relay1On = false;
}
return true;
}//
// Alexa Power State Callback for Relay 2
bool onPowerState2(const String &deviceId, bool &state) {
if (state) {
startWateringCycle(2); // Start watering cycle for relay 2
} else {
digitalWrite(RELAY2_PIN, LOW);
relay2On = false;
}
return true;
}
HiStill the same app says it's on when serial says off and zone 1 changed from on to off it changed zone2 aswellRegards colin
Sent from Sky Yahoo Mail on Android
On Thu, Jun 13, 2024 at 9:01, Aruna @.***> wrote:
Check the code marked as / CHANGED: Update server with new status / for example how to update the server
// Define the pins
// WiFi and Server AsyncWebServer server(80);
// Watering schedule (in milliseconds) const unsigned long interval = 1 60 60 1000; // 6 hours (4 times a day)changed to1 const unsigned long relayOnDuration = 10 60 * 1000; // 10 minutes
// Timers unsigned long previousMillis = 0; unsigned long relay1StartMillis = 0; unsigned long relay2StartMillis = 0;
// Watering state bool relay1On = false; bool relay2On = false;
// Watering times unsigned long lastWateringStartTime = 0; unsigned long nextWateringStartTime = interval;
// SinricPro
// Function prototypes void setupWifi(); void handleButtonPress(); void notifyPhone(bool state); void startWateringCycle(int relayNum); bool onPowerState1(const String &deviceId, bool &state); bool onPowerState2(const String &deviceId, bool &state); void setupSinricPro();
void setup() { Serial.begin(115200); pinMode(RELAY1_PIN, OUTPUT); pinMode(RELAY2_PIN, OUTPUT); pinMode(BUTTON_PIN, INPUT_PULLUP); digitalWrite(RELAY1_PIN, LOW); digitalWrite(RELAY2_PIN, LOW);
setupWifi();
// Button press interrupt attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), handleButtonPress, FALLING);
server.begin(); setupSinricPro();
Serial.println("Setup complete"); }
void loop() { unsigned long currentMillis = millis(); SinricPro.handle();
// Check if it's time to start a new watering cycle if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; startWateringCycle(1); // Start watering cycle for relay 1
Serial.println("Watering cycle for relay 1 started");
}
// Check if relay1 should turn off and relay2 should turn on if (relay1On && (currentMillis - relay1StartMillis >= relayOnDuration)) { digitalWrite(RELAY1_PIN, LOW); relay1On = false; relay2StartMillis = currentMillis;//delay digitalWrite(RELAY2_PIN, HIGH); relay2On = true;
/* CHANGED: Update server with new status */
SinricProSwitch& mySwitch1 = SinricPro[SWITCH_ID_RELAY1];
mySwitch1.sendPowerStateEvent(false);
SinricProSwitch& mySwitch2 = SinricPro[SWITCH_ID_RELAY2];
mySwitch2.sendPowerStateEvent(true);
notifyPhone(true); // Notification for relay 2 on
Serial.println("Relay 1 turned off, Relay 2 turned on");
}
// Check if relay2 should turn off if (relay2On && (currentMillis - relay2StartMillis >= relayOnDuration)) { digitalWrite(RELAY2_PIN, LOW);
/* CHANGED: Update server with new status */
SinricProSwitch& mySwitch2 = SinricPro[SWITCH_ID_RELAY2];
mySwitch2.sendPowerStateEvent(true);
relay2On = false;
notifyPhone(false); // Notification for relay 2 off
Serial.println("Relay 2 turned off");
} }
// Start the watering cycle for the specified relay void startWateringCycle(int relayNum) { if (relayNum == 1) { relay1StartMillis = millis(); digitalWrite(RELAY1_PIN, HIGH); relay1On = true; notifyPhone(true); // Notification for relay 1 on } else if (relayNum == 2) { relay2StartMillis = millis(); digitalWrite(RELAY2_PIN, HIGH); relay2On = true; notifyPhone(true); // Notification for relay 2 on } }
// Handle button press for manual override void handleButtonPress() { if (relay1On || relay2On) { digitalWrite(RELAY1_PIN, LOW); digitalWrite(RELAY2_PIN, LOW); relay1On = false; relay2On = false; notifyPhone(false);
/* CHANGED: Update server with new status */
SinricProSwitch& mySwitch1 = SinricPro[SWITCH_ID_RELAY1];
mySwitch1.sendPowerStateEvent(false);
SinricProSwitch& mySwitch2 = SinricPro[SWITCH_ID_RELAY2];
mySwitch2.sendPowerStateEvent(false);
Serial.println("Watering cycle stopped");
} else { startWateringCycle(1); // Start watering cycle for relay 1 Serial.println("Manual watering cycle for relay 1 started"); } }
// Notify phone via a simple web server message (simplified) void notifyPhone(bool state) { // Implement your notification logic here (e.g., HTTP request to a notification service) Serial.print("Notification: "); Serial.println(state ? "ON" : "OFF"); }
// Setup Wi-Fi void setupWifi() { Serial.println("Connecting to WiFi..."); WiFi.begin("xxx", "xxx");
while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.print("."); }
Serial.println(); Serial.print("Connected to WiFi. IP address: "); Serial.println(WiFi.localIP());
// Set up a simple web server to display the status
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
String response = "Relay 1: " + String(relay1On ? "ON" : "OFF") + "
";
response += "Relay 2: " + String(relay2On ? "ON" : "OFF") + "
";
response += "Last Watering: " + String(lastWateringStartTime) + "
";
response += "Next Watering: " + String(nextWateringStartTime);
request->send(200, "text/html", response);
});
}
// Setup SinricPro void setupSinricPro() { SinricProSwitch& mySwitch1 = SinricPro[SWITCH_ID_RELAY1]; mySwitch1.onPowerState(onPowerState1);
SinricProSwitch& mySwitch2 = SinricPro[SWITCH_ID_RELAY2]; mySwitch2.onPowerState(onPowerState2);
SinricPro.begin(APP_KEY, APP_SECRET); }
// Alexa Power State Callback for Relay 1 bool onPowerState1(const String &deviceId, bool &state) { if (state) { startWateringCycle(1); // Start watering cycle for relay 1 } else { digitalWrite(RELAY1_PIN, LOW); relay1On = false; } return true; }// // Alexa Power State Callback for Relay 2 bool onPowerState2(const String &deviceId, bool &state) { if (state) { startWateringCycle(2); // Start watering cycle for relay 2 } else { digitalWrite(RELAY2_PIN, LOW); relay2On = false; } return true; }
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
If I change zone1 sends noti that it's turned on but serial stays the same and button says it's offRegards colin
Sent from Sky Yahoo Mail on Android
On Thu, Jun 13, 2024 at 9:33, @.**@.> wrote: HiStill the same app says it's on when serial says off and zone 1 changed from on to off it changed zone2 aswellRegards colin
Sent from Sky Yahoo Mail on Android
HiJust tried from different location it send noti to say it changed from on to off but button on app stays on on the opposite back home in 30 mins to see if it has changed on serial I keep tryingRegards colin
Sent from Sky Yahoo Mail on Android
On Thu, Jun 13, 2024 at 9:38, @.**@.> wrote: If I change zone1 sends noti that it's turned on but serial stays the same and button says it's offRegards colin
Sent from Sky Yahoo Mail on Android
On Thu, Jun 13, 2024 at 9:33, @.**@.> wrote: HiStill the same app says it's on when serial says off and zone 1 changed from on to off it changed zone2 aswellRegards colin
Sent from Sky Yahoo Mail on Android
Just tried again if I press zone1 button it changes zone2 on noti and not zone1Colin
Sent from Sky Yahoo Mail on Android
On Thu, Jun 13, 2024 at 10:16, @.**@.> wrote: HiJust tried from different location it send noti to say it changed from on to off but button on app stays on on the opposite back home in 30 mins to see if it has changed on serial I keep tryingRegards colin
Sent from Sky Yahoo Mail on Android
HiNormal code works as in ater 1 hr relay1 or zone1 turns on after 10mins that stops and relay2 or zone2 starts for 10mins I wondered because of that code is that what buttons are trying to do and not work independentlyRegards colin
Sent from Sky Yahoo Mail on Android
On Thu, Jun 13, 2024 at 10:30, @.**@.> wrote: Just tried again if I press zone1 button it changes zone2 on noti and not zone1Colin
Sent from Sky Yahoo Mail on Android
It’s difficult to keep up with what’s going over there. Seems you have downloaded someone else sketch and having a hard time tinkering it
I recommend to
Yes your right its not all mine have told alexa to turn zone one on it came on but turned zone2 on straight after so looks like running normal code zone1 then zone2 I'll keep testing and trying many thanksColin
Sent from Sky Yahoo Mail on Android
On Thu, Jun 13, 2024 at 11:54, Aruna @.***> wrote:
It’s difficult to keep up with what’s going over there. Seems you have downloaded someone else sketch and having a hard time tinkering it
I recommend to
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
Prob has got something with setpowerstate I thinkColin
Sent from Sky Yahoo Mail on Android
On Thu, Jun 13, 2024 at 11:59, @.**@.> wrote: Yes your right its not all mine have told alexa to turn zone one on it came on but turned zone2 on straight after so looks like running normal code zone1 then zone2 I'll keep testing and trying many thanksColin
Sent from Sky Yahoo Mail on Android
This issue has gone quiet. Spooky quiet. We currently close issues after 14 days of inactivity. It’s been at least 7 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. As a friendly reminder, the best way to fix this or any other problem is to provide a detailed error description including a serial log. Thanks for being a part of the SinricPro community!
Hey again! It’s been 14 days since anything happened on this issue, so our friendly robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY
. Please feel free to comment on this issue or create a new one if you need anything else. As a friendly reminder, the best way to fix this or any other problem is to provide a detailed error description including a serial log. Thanks again for being a part of the SinricPro community!
``
have downloaded this sketch and setup sinric pro for 2 buttons to operate 2 relays ,at first notifications were sent but app says button1 is off when it actually was on and button 2 was sometimes right with serial ,the code waters every hr relay1 waters for 10mins then stops and relay2 waters for 10minns then waitsfor next watering time that works fine and says on serial screen the correct info its just the app that doesnt,is there something not right with code or am i doing something wrong,if i go to webserver it works fine,wifi good aswell,any ideas please colin