Controlling 4 relays using google home

rosh8097
Posts: 8
Joined: Sun May 30, 2021 3:56 pm

Hello,
I am new with supla I want to control 4 Relays using google home app and assistant how can I do that ?
please Help stepwise I have esp8266 and want to program it with Arduino IDE so someone plzz help me with that
User avatar
klew
Posts: 8179
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław

Hi

Please install SuplaDevice from library manager. You can start with SequenceButton example.
There are two relays already defined - you can add two more in similar way.
(You can remove SequenceButton related code from this example)
Widzimy się na Supla Offline Party vol. 2 :!:
rosh8097
Posts: 8
Joined: Sun May 30, 2021 3:56 pm

klew wrote: Mon May 31, 2021 7:35 pm Hi

Please install SuplaDevice from library manager. You can start with SequenceButton example.
There are two relays already defined - you can add two more in similar way.
(You can remove SequenceButton related code from this example)
Thank you so much for ur help
Is there any way through which I can also control these relays with manual switches and get real-time feedback of the relays on app?
User avatar
klew
Posts: 8179
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław

rosh8097 wrote: Sun Jun 06, 2021 5:48 am Thank you so much for ur help
Is there any way through which I can also control these relays with manual switches and get real-time feedback of the relays on app?
Yes, there is a Button class available.
Just add:

Code: Select all

#incldue <supla/control/relay.h>
#include <supla/control/button.h>

// in setup:
auto r1 = new Supla::Control::Relay(relay_gpio);
auto b1 = new Supla::Control::Button(button_gpio, pullup, invert_logic); 

b1->addAction(Supla::TOGGLE, r1, Supla::ON_PRESS);
This should toggle state of r1 relay everytime you press button b1. "Standard" logic for button class is LOW - button released, HIGH - button pressed. If you use pullup for button, then this logic should be inverted (put true argument for invert_logic parameter).

You can configure many actions on button (just repeat this "b1->addAction..." row with different set of parameters).
Here you can find all types of actions allowed by Relay class (https://github.com/SUPLA/supla-arduino/ ... y.cpp#L126)
And here you can find all possible events that can happen in button class - check all rows with "runAction" method (https://github.com/SUPLA/supla-arduino/ ... on.cpp#L31)

You can also add multiple buttons.
Widzimy się na Supla Offline Party vol. 2 :!:
rosh8097
Posts: 8
Joined: Sun May 30, 2021 3:56 pm

Thank you so much again, you are great man!
rosh8097
Posts: 8
Joined: Sun May 30, 2021 3:56 pm

Brother can u please help me with one more thing

Actually I want to Control stepper motor with supla for my blinds I have seen rollershuter example but it won't work since it triggers relay I want to Control stepper motor so can you help me with that?
User avatar
klew
Posts: 8179
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław

rosh8097 wrote: Wed Jun 09, 2021 3:48 pm Brother can u please help me with one more thing

Actually I want to Control stepper motor with supla for my blinds I have seen rollershuter example but it won't work since it triggers relay I want to Control stepper motor so can you help me with that?
What exactly do you want to achive with stepper motor? Usually those devices allow to set some specific angle, but they don't rotate. Do you want to set only tilt for blinds?
Widzimy się na Supla Offline Party vol. 2 :!:
rosh8097
Posts: 8
Joined: Sun May 30, 2021 3:56 pm

I want to rotate the stepper motor
User avatar
klew
Posts: 8179
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław

rosh8097 wrote: Thu Jun 10, 2021 12:34 pm I want to rotate the stepper motor
If you want to rotate it, then you have to modify stepper motor HW. By default those devices have blockade and they can't do multiple rotations. I also heard that some control unit has to be removed and in the end we end up with two cables, which you can control as a standard "roller shutter" from Supla (providing voltage on one cable rotates in one direction, and providing it for second cable rotates in another direction).
Widzimy się na Supla Offline Party vol. 2 :!:
elmaya
Posts: 1482
Joined: Wed Jun 27, 2018 5:48 pm
Location: El Saucejo - Sevilla

you can do with "Supla: Io" here is an example:

Code: Select all

/*
  Copyright (C) AC SOFTWARE SP. Z O.O.
  
  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include <SPI.h>
#include <SuplaDevice.h>
#include <supla/control/roller_shutter.h>
#include <supla/network/esp_wifi.h>
Supla::ESPWifi wifi("your_wifi_ssid", "your_wifi_password");

class CustomControl : public Supla::Io {
 public:
  void customDigitalWrite(int channelNumber, uint8_t pin, uint8_t val) {
   
    if (pin == 46) {  // Pin 46 = number that we have defined for first RollerShutter relay
      if (val){  
        Serial.println("RollerShutter MOVE UP");
        
        // put here your code to start the opening movement.
        
      }else{
        Serial.println("RollerShutter STOP UP");
        
        // put here your code to stop movement.  
             
      }
      return;
     }
    if (pin == 47) {  // Pin 47 = number that we have defined for second RollerShutter relay
      if (val){  
        Serial.println("RollerShutter MOVE DOWN");
        
        // put here your code to start the closing movement.
        
      }else{
        Serial.println("RollerShutter STOP DOWN");
        
        // put here your code to stop movement.
        
      }
      return;
     }
    return ::digitalWrite(pin, val);
  }    
} CustomControl;

void setup() {

  Serial.begin(115200);

  // Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
  char GUID[SUPLA_GUID_SIZE] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

  // Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
  char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
 

  new Supla::Control::RollerShutter(46, 47, true); 


  wifi.enableSSL(false);
  SuplaDevice.begin(GUID,              // Global Unique Identifier 
                    "svr1.supla.org",  // SUPLA server address
                    "email@address",   // Email address used to login to Supla Cloud
                    AUTHKEY);          // Authorization key
    
}

void loop() {
  SuplaDevice.iterate();
}
Post Reply

Return to “Help”