Hello Everyone!!!
I have been trying hard to figure out if there is a way to find out current state of GPIO’s on ESP8266/32 and update Alexa skills.
The ideas are:
1. if I am working on Alexa and manual switch, I get options to update with virtual relay etc. But if I am working with 2 parallel software like Alexa skill and Blynk (or any other application), and if I operate the GPIO (relays etc) with second software, Supla skill on Alexa App doesn’t show the change.
2. For any reason, if I am away from home, and operating on GSM, and a reboot or such incident happens, if I open Alexa App, it shows precious state and not the updated one (please consider I am not using FS to store precious GPIO state)
Your help would be appreciated, as trying to work this out for a long time.
Many thanks in advance.
Update the Current state of GPIO to Supla Amazon Skill
-
- Posts: 19589
- Joined: Tue Jan 19, 2016 9:26 am
- Location: Paczków
Are you using a public or private server? What channel function do you have set up? Does a change of the relay state change the state in the Supla application?
-
- Posts: 11
- Joined: Tue Feb 22, 2022 11:50 pm
Thanks for your response.
I am current using Supla Cloud for testing.
Edit:
In Blynk we use Blynk.syncVirtual(V0) or smilar to update GPIO (Virtual or physical) Status, similarly for HomeKit we use characteristic_notify() function. Do we have any function in Supla similar to this?
Are you using a public or private server?
I am current using Supla Cloud for testing.
I have left the channel default on cloud. And as well left default in program as per Supla Device Relay example.What channel function do you have set up?
I haven’t noticed that, my miss. Would update you shortly on this.Does a change of the relay state change the state in the Supla application?
Edit:
I checked, it doesn't change the state of switch in Supla Aplication.Does a change of the relay state change the state in the Supla application?
In Blynk we use Blynk.syncVirtual(V0) or smilar to update GPIO (Virtual or physical) Status, similarly for HomeKit we use characteristic_notify() function. Do we have any function in Supla similar to this?
it raised a query within. Do we have to set different channel manually for every SuplaDevice(), irrespective of multiple device in single ESP or single device per ESP?What channel function do you have set up?
-
- Posts: 11
- Joined: Tue Feb 22, 2022 11:50 pm
It's a simple code which i am running.
main.ino - where BLYNK related definitions are written (plus supla wifi initialisation)
suplaDefion.h - included in mail.ino
Here is the code i am using for <suplaDefion.h>
I am able to connect to supla cloud, and can operate from cloud console as well as supla application. But if i use another parallel program like BLYNK, for example, and compile together here is my observations:
1. Both applications works flawlessly in parallel on same device
2. if i update status from supla cloud/app, i get updated switch status in Blynk app
3. if i update from blynk app, i dont get the updated switch status in Supla Cloud/App console
Do let me know if you you need more detail on this...
main.ino - where BLYNK related definitions are written (plus supla wifi initialisation)
suplaDefion.h - included in mail.ino
Here is the code i am using for <suplaDefion.h>
Code: Select all
#include <SuplaDevice.h>
#include <supla/control/relay.h>
#include <supla/network/esp_wifi.h>
const char *ssid = ""; //managed by wifiManager in main.ino, purposefully kept blank
const char *password = ""; //managed by wifiManager in main.ino, purposefully kept blank
const char *server = "svr**.supla.org";
const char *mailid = "****@****.com";
// Supla::ESPWifi wifi(ssid, password); // initiated in main.ino
#define PIN_SWITCH 3 // 2 // 5
void setup() {
// Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
char GUID[SUPLA_GUID_SIZE] = {*********************************************};
// Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {*********************************************};
auto secretRelay = new Supla::Control::Relay(PIN_SWITCH, true); // High level trigger relay on pin_switch
SuplaDevice.begin(GUID, server, mailid, AUTHKEY);
}
void loop() {
SuplaDevice.iterate();
}
1. Both applications works flawlessly in parallel on same device
2. if i update status from supla cloud/app, i get updated switch status in Blynk app
3. if i update from blynk app, i dont get the updated switch status in Supla Cloud/App console
Do let me know if you you need more detail on this...
-
- Posts: 11230
- Joined: Thu Jun 27, 2019 12:16 pm
- Location: Wrocław
I'm not sure if I understood you correctly.
Are you running two separate programs on one device? Or is it just single application, but you put some Supla and some Blynk code together?
SuplaDevice is not checking any GPIO state - it assumes that only it controlls the GPIO, so checking its state is not needed.
If you want to put another part of application that will control GPIO by itself then I recommend, to replace that "Relay" class in Supla with "VirtualRelay".
VirtualRelay doesn't attach to any physical GPIO and instead it just keepds its state in memory.
You can get and set state of such "relay" by:
You will have to use above commads to notify state change of actual relay to Supla.
There is also option to register for notification from relay state change, so you'll not have to check state manually.
Are you running two separate programs on one device? Or is it just single application, but you put some Supla and some Blynk code together?
SuplaDevice is not checking any GPIO state - it assumes that only it controlls the GPIO, so checking its state is not needed.
If you want to put another part of application that will control GPIO by itself then I recommend, to replace that "Relay" class in Supla with "VirtualRelay".
VirtualRelay doesn't attach to any physical GPIO and instead it just keepds its state in memory.
You can get and set state of such "relay" by:
Code: Select all
auto vrelay = new Supla::Control::VirtualRelay();
...
vrelay->isOn(); // returns status
vrelay->turnOn();
vrelay->turnOff();
There is also option to register for notification from relay state change, so you'll not have to check state manually.
-
- Posts: 11
- Joined: Tue Feb 22, 2022 11:50 pm
@klew
Thanks for your response. Much appreciated.
Presuming, I am controlling physical GPIO pin state with Supla relay(), and monitoring the state of same GPIO by mapping with vRelay(), how to map the vRelay() with GPIO? I couldn’t find any document or function definition on the forum.
For example:
And based on vRelay status, update supla application status.?
OR:
Do we have any update function in Supla which reads GPIO status and update periodically to Supla Application (an example, a reboot on ESP board, won’t change the GPIO status on Supla APP. Before reboot, if the state was on, and after reboot is state is off, Supla App still shows it’s ON). This would solve no only this scenario, but real-time issue also on standalone Supla instances.
Thanks for your response. Much appreciated.
I am running Blynk and Supla code together in same device parallel. A test which I am performing for intercommunion with existing running home automation setup add-on with Supla, to control along with Blynk or other applications.I'm not sure if I understood you correctly.
Are you running two separate programs on one device? Or is it just single application, but you put some Supla and some Blynk code together?
Sounds a solution to the scenario. I read somewhere in the forum about virtual relay, but couldn’t pin down to any document or help on the function. Thanks for your suggestion. I have one query to implement this and try:VirtualRelay doesn't attach to any physical GPIO and instead it just keepds its state in memory.
You can get and set state of such "relay" by:Code: Select all
auto vrelay = new Supla::Control::VirtualRelay(); ... vrelay->isOn(); // returns status vrelay->turnOn(); vrelay->turnOff();
Presuming, I am controlling physical GPIO pin state with Supla relay(), and monitoring the state of same GPIO by mapping with vRelay(), how to map the vRelay() with GPIO? I couldn’t find any document or function definition on the forum.
For example:
Code: Select all
If (GPIO_Pin == HIGH){
vRelay(isON);
}
else{
vRelay(isOFF)
}
OR:
Do we have any update function in Supla which reads GPIO status and update periodically to Supla Application (an example, a reboot on ESP board, won’t change the GPIO status on Supla APP. Before reboot, if the state was on, and after reboot is state is off, Supla App still shows it’s ON). This would solve no only this scenario, but real-time issue also on standalone Supla instances.
-
- Posts: 11230
- Joined: Thu Jun 27, 2019 12:16 pm
- Location: Wrocław
Why do you need it? On Supla Cloud you can enable MQTT integration which will publish all channels to MQTT broker.durobhash wrote: Fri Mar 04, 2022 10:30 am I am running Blynk and Supla code together in same device parallel. A test which I am performing for intercommunion with existing running home automation setup add-on with Supla, to control along with Blynk or other applications.
It should be easier to integrate over MQTT instead of writing device application that works on few interfaces at the same time. Also you can integrate Supla with Alexa without touching Supla devices.
Virtual relay is not linked to any GPIO. You can distinquish mutliple virtual relays in your program directly by using variables, i.e.durobhash wrote: Fri Mar 04, 2022 10:30 am Presuming, I am controlling physical GPIO pin state with Supla relay(), and monitoring the state of same GPIO by mapping with vRelay(), how to map the vRelay() with GPIO? I couldn’t find any document or function definition on the forum.
For example:And based on vRelay status, update supla application status.?Code: Select all
If (GPIO_Pin == HIGH){ vRelay(isON); } else{ vRelay(isOFF) }
Code: Select all
auto vr1 = new Supla::Control::VirtualRelay();
auto vr2 = new Supla::Control::VirtualRelay();
auto vr3 = new Supla::Control::VirtualRelay();
Code: Select all
if (GPIO_1_value == HIGH) {
vr1->turnOn();
} else {
vr2->turnOff();
}
if (GPIO_2_value == HIGH) {
vr2->turnOn();
} else {
vr2->turnOff();
}
... // etc
If you want to use GPIO as an input, then check Supla::Sensor::Binary class ( https://github.com/SUPLA/supla-arduino/ ... r/binary.h ).durobhash wrote: Fri Mar 04, 2022 10:30 am Do we have any update function in Supla which reads GPIO status and update periodically to Supla Application (an example, a reboot on ESP board, won’t change the GPIO status on Supla APP. Before reboot, if the state was on, and after reboot is state is off, Supla App still shows it’s ON). This would solve no only this scenario, but real-time issue also on standalone Supla instances.
It will read GPIO and show it as sensor on Supla with ON/OFF state.
About state of GPIO after restart: Supla always initialize GPIO for configured channels and updates that state to Supla server. App should not show that it is "still ON". In your simple program, there is no storage memory configured, so Relay will always be set to "off" during startup.
-
- Posts: 11
- Joined: Tue Feb 22, 2022 11:50 pm
Thanks for your feedback
I am unaware if there is a possibility to allocate storage memory is FS through Supla Device examples. If any, kindly guide me though. However would try to create additional variable and try storage memory.
Few existing applications, like Apple HomeKit Devices and few more doesn’t allow to communicate over MQTT, they are in close looped ecosystems (and may be homebridge etc are way to some extend). That’s where I was trying this out of the device itself.Why do you need it? On Supla Cloud you can enable MQTT integration which will publish all channels to MQTT broker.
It should be easier to integrate over MQTT instead of writing device application that works on few interfaces at the same time. Also you can integrate Supla with Alexa without touching Supla devices
Thanks, would try this out along with vRelay() and come back with update.If you want to use GPIO as an input, then check Supla::Sensor::Binary class ( https://github.com/SUPLA/supla-arduino/ ... r/binary.h ).
It will read
My concern was about real-time update of GPIO status out of the box way on Supla App after a reboot, not storage memory.In your simple program, there is no storage memory configured, so Relay will always be set to "off" during startup.
I am unaware if there is a possibility to allocate storage memory is FS through Supla Device examples. If any, kindly guide me though. However would try to create additional variable and try storage memory.
-
- Posts: 11230
- Joined: Thu Jun 27, 2019 12:16 pm
- Location: Wrocław
There are 3 options for initial Relay state in Supla:
1. init to "HIGH"
2. init to "LOW"
3. restore state which was before reboot
You could try to read GPIO state before calling SuplaDevice.begin() method and then after that line, call something like:
This may be usefull if another part of your program will configure GPIO in earlier stage before calling to SuplaDevice.begin().
Here is link to forum about storage viewtopic.php?t=7162 (in Polish, but it is only few lines of code, so should be easy).
On ESP8266 please use "eeprom" variant - it uses eeprom emluation library on ESP's flash.
Once you have storage added to your project, you can configure relay (or virtual relay) to restore it's last state before the reboot:
Here (https://github.com/SUPLA/supla-arduino/ ... elay.h#L49) is a list of all options that configure relay initial state. Those methods will work on Relay and all derived classes like VirtualRelay.
1. init to "HIGH"
2. init to "LOW"
3. restore state which was before reboot
You could try to read GPIO state before calling SuplaDevice.begin() method and then after that line, call something like:
Code: Select all
if (gpio1_value == HIGH) {
relay1->turnOn();
} else {
relay1->turnOff();
}
Here is link to forum about storage viewtopic.php?t=7162 (in Polish, but it is only few lines of code, so should be easy).
On ESP8266 please use "eeprom" variant - it uses eeprom emluation library on ESP's flash.
Once you have storage added to your project, you can configure relay (or virtual relay) to restore it's last state before the reboot:
Code: Select all
relay->setDefaultStateRestore();