mai 1

Domotique avec Google Home et Photon

Amélioration/simplification de mon 1er projet domotique.
Plus besoin de serveur Blynk, remplacé par le cloud de Particle.
Le Teensy est remplacé par Photon, qui contient une puce WiFi donc plus besoin de ESP-01 et donc de régulateur 3.3 volts.

J’ai modifié aussi le code qui permet maintenant d’envoyer deux mots clés via Google Home pour déclencher une action.

Le but étant de piloter les télécommandes infra-rouge (ampli 5.1, switch HDMI…) , la Freebox, les lampes de la maison (via des prises commandés en 433mhz) et un ruban LED multicolore via mon Google Home.
Tout le montage rentre dans un bocal translucide de chez Ikea. La consommation au repos est de 1.9 Watts.

Photon dans bocal IKEA

Pré-requis

Composants :

  • Particle Photon
  • XY-FST-433 (RX433)
  • SFH4346 (LED infra-rouge)
  • WS2812 (ruban LED)
  • Condensateur 1000 uF/25V
  • Transfo 5 Volts /2A
  • Éventuellement, un relais 220V/RX433

Le Principe

IFTTT reçoit les commandes du Google Home (trigger) et l’envoie une URL (WebHook) sur le cloud Particle.
Le micro-contrôleur Photon, relié en WiFi,  déclenche des actions infra-rouge et radio-fréquence, via le code Arduino.

Ex : On dit : Allume et un mot clé (tout, le guéridon, le lampadaire, la télé…), le code Arduino contient des IF qui réagissent aux mot clés indiqués et envoie les codes infra-rouge ou 433mhz.

Le Photon

La connexion du Photon au WiFi est simplissime :

  • Brancher en USB
  • installer l’appli Android,
  • connecter le smartphone au WiFi du Photon
  • indiquer le SSID/clé de son WiFi

Une fois fait, le Photon est accessible via le cloud Particle.

Le code Arduino

Pas besoin de passer par l’installation de Arduino, tous se passe en ligne via le cloud Particle. L’avantage est de pouvoir mettre à jour le code du Photon directement en WiFi !

Il faut juste intégrer les librairies :

  • IRtransmitter
  • RCSwitch
  • NEOpixel
  • rest_client

Juste à modifier IRTransmitter.ccp pour pouvoir envoyer des code infra-rouge à la suite.

}
digitalWrite(led_pin_, LOW);
delay(10); //temps minimum entre deux envoie de code infra rouge
}

On peut ajouter manuellement une library (petit « + »), les deux fichiers ***.cpp et ***.h qui la compose seront liés et ajoutés automatiquement au fichier ***.ino
ex : #include « IRTransmitter.h »
#include « IRTransmitter.cpp »
Copier/coller dedans le code de la librairy, précédement récupéré sur GitHub
(bizz, le code copier dans ***.cpp, se retrouve dans ***.h et vice versa)
L’avantage c’est que l’on pourra éditer les library et que, lors de l’export du projet, on aura dans le zip le fichier .ino et les library utilisées

// Webhook
#include "rest_client.h"
RestClient client = RestClient("hd1.freebox.fr");

// WS2812
#include "neopixel.h"
#define PIXEL_PIN D2 // pin de la broche Din du WS2812
#define PIXEL_COUNT 55 // nombre de LED
#define PIXEL_TYPE WS2812B
#define BRIGHTNESS 255 // lumière, de 0 à 255
int VitesseAllume = 20;
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

// InfraRouge
#include "IRTransmitter.h"
#define IR_PIN D6 // pin LED InfraRouge
#define LED_PIN D7 // LED interne à chaque envoie de code
IRTransmitter transmitter(IR_PIN, LED_PIN);

// RX433
#include "RCSwitch.h"
RCSwitch mySwitch = RCSwitch();


void setup() {//SETUP

IPAddress myIP = WiFi.localIP(); // publier l'adresse IP
Particle.publish("IP du Photon", String(myIP), PRIVATE);

pinMode(D7, OUTPUT); // LED interne

mySwitch.enableTransmit(D0);// PIN data du module RX433

strip.setBrightness(BRIGHTNESS);
strip.begin();
strip.show(); // démarrer LED éteintes

// enregistrement de la fonction dans le cloud Particle.
// Le 1er terme sera appelé dans IFTTT, le second contient le TextField de IFTTT
Particle.function("allume", MotAllume);
Particle.function("eteint", MotEteint);
Particle.function("AmpliAction", ActionAmpli);
Particle.function("AmpVolPlus", DBenPlus);
Particle.function("AmpVolMoins", DBenMoins);
Particle.function("voir", regarder);
Particle.function("BonneNuit", EteintTout);

}//fin setup

/*** CODES INFRAROUGE ***/
//Ampli 5.1
unsigned int  Ampli_OnOff[67] = {8550,4200, 600,1500, 600,500, 600,1500, 600,500, 600,450, 600,1550, 600,450, 600,1550, 600,450, 600,1550, 600,450, 650,1500, 600,1550, 600,450, 600,1550, 600,450, 600,500, 550,500, 600,1550, 600,1500, 650,1500, 600,450, 600,500, 600,450, 600,1550, 600,1500, 600,500, 600,450, 600,450, 600,1550, 600,1550, 600,1550, 600};  // NEC A55A38C7

unsigned int  Ampli_VolPlus[67] = {8500,4200, 600,1550, 600,500, 550,1550, 600,500, 550,500, 600,1550, 550,500, 600,1550, 550,500, 600,1550, 600,450, 600,1550, 600,1500, 600,500, 600,1500, 600,500, 600,450, 600,1550, 600,450, 600,1550, 600,450, 600,500, 550,500, 600,450, 600,1550, 600,450, 600,1550, 600,500, 550,1550, 600,1550, 600,1550, 550,1550, 700};  // NEC A55A50AF  

unsigned int  Ampli_VolMoins[67] = {8550,4200, 600,1550, 600,450, 600,1550, 600,450, 600,500, 600,1500, 650,450, 600,1500, 650,450, 600,1550, 550,500, 600,1550, 600,1500, 600,500, 600,1500, 650,450, 600,1500, 650,1500, 600,500, 550,1550, 600,500, 550,500, 600,450, 600,500, 600,450, 600,450, 650,1500, 600,450, 600,1550, 600,1550, 600,1550, 550,1550, 600};  // NEC A55AD02F

unsigned int  Ampli_Mute[67] = {8550,4200, 600,1500, 600,500, 600,1500, 600,500, 600,450, 600,1550, 600,450, 600,1550, 600,450, 600,1550, 600,450, 600,1550, 600,1550, 600,450, 600,1550, 600,450, 600,500, 550,1550, 600,500, 550,500, 550,1600, 600,450, 600,450, 600,500, 550,1550, 600,500, 550,1600, 550,1550, 600,500, 550,1550, 600,1550, 600,1550, 600};  // NEC A55A48B7

unsigned int  Ampli_Loudness[67] = {8550,4200, 550,1550, 600,500, 600,1500, 600,500, 600,450, 600,1550, 600,450, 600,1550, 600,450, 600,1550, 600,450, 600,1550, 600,1550, 600,450, 600,1550, 600,450, 600,1550, 600,1550, 550,1550, 600,1550, 600,1550, 600,450, 600,450, 600,1550, 600,500, 550,500, 600,450, 600,500, 550,500, 600,1550, 600,1500, 600,500, 600};  // NEC A55AF906

//Switch HDMI
unsigned int  SwitchHDMI1[67] = {9100,4450, 600,550, 600,600, 600,550, 600,550, 600,550, 600,550, 600,600, 600,550, 600,1650, 600,1650, 600,1650, 650,1600, 650,1600, 650,1650, 600,1650, 600,1650, 600,550, 650,550, 600,1650, 600,550, 600,550, 650,500, 650,550, 600,550, 600,1650, 650,1600, 650,500, 650,1650, 600,1650, 600,1650, 650,1600, 650,1600, 650};  // NEC FF20DF

unsigned int  SwitchHDMI2[67] = {9200,4400, 650,550, 600,550, 600,550, 600,600, 600,550, 600,550, 600,550, 600,550, 650,1600, 650,1600, 650,1650, 600,1650, 600,1650, 600,1650, 650,1600, 650,1600, 650,550, 600,550, 600,550, 600,1650, 600,600, 600,550, 600,550, 600,550, 600,1650, 600,1650, 600,1650, 600,550, 600,1650, 650,1600, 650,1600, 650,1600, 650};  // NEC FF10EF

unsigned int  SwitchHDMI3[67] = {9200,4400, 600,550, 650,500, 650,500, 650,500, 600,600, 550,600, 600,550, 650,500, 600,1650, 600,1650, 600,1650, 600,1650, 600,1650, 600,1650, 650,1600, 650,1600, 650,500, 650,1600, 650,500, 650,1600, 650,500, 650,550, 600,550, 600,550, 600,1650, 600,550, 600,1650, 600,550, 600,1650, 600,1650, 600,1650, 600,1650, 600};  // NEC FF50AF

void loop() {

}//fin loop

/*** Ampli 5.1 ***/
int ActionAmpli(String action){

  if(action == "mute"){// coupe/remet/mute l'ampli
  transmitter.Transmit(Ampli_Mute, sizeof(Ampli_Mute) / sizeof(Ampli_Mute[0]));  
  return 1;
  }
  if(action == "loudness"){
  transmitter.Transmit(Ampli_Loudness, sizeof(Ampli_Loudness) / sizeof(Ampli_Loudness[0]));  
  return 1;
  }
}//

int DBenPlus(String action){// monte l'ampli de **
int volume = action.toInt();

 if(volume >=0 || volume <=10){// pour empécher de mettre trop fort !
      
    for (int i=1; i <= volume; i++){
     transmitter.Transmit(Ampli_VolPlus, sizeof(Ampli_VolPlus) / sizeof(Ampli_VolPlus[0]));
     delay(100);
    }
    return volume;    
 }
}//

int DBenMoins(String action){// monte l'ampli de **
int volume = action.toInt();

    for (int i=1; i <= volume; i++){
     transmitter.Transmit(Ampli_VolMoins, sizeof(Ampli_VolMoins) / sizeof(Ampli_VolMoins[0]));
     delay(100);
    }
    return volume;    
}//

/*** REGARDER ***/
int regarder(String action){
String mot[2];
    mot[0]="";
    mot[1]="";

    int index = 0;
    for( int i = 0; i < action.length(); i++ ){
        
      if( index < 2 ){// on sépare les mots reçus
        char sep = action.charAt(i);
        mot[index] += sep;

      if( sep == ' ') index++;// si il y a un espace entre
      }
    }
//Switch HDMI
  if(mot[0] == "la" || mot[1] == "freebox"){
  transmitter.Transmit(SwitchHDMI1, sizeof(SwitchHDMI1) / sizeof(SwitchHDMI1[0]));  
  return 1;
  }
  if(mot[0] == "Netflix" or mot[0] == "le" || mot[1] == "Chromecast"){
  transmitter.Transmit(SwitchHDMI2, sizeof(SwitchHDMI2) / sizeof(SwitchHDMI2[0]));  
  return 1;
  }
  if(mot[0] == "Kodi" or mot[0] == "le" || mot[1] == "mediacenter"){
  transmitter.Transmit(SwitchHDMI3, sizeof(SwitchHDMI3) / sizeof(SwitchHDMI3[0]));  
  return 1;
  }

// Chaines Freebox 
if (action == "mosaïque" or action == "mosaîc" or action == "panel") {TelecomFreebox ("0","","");}
if (action == "TF 1") {TelecomFreebox ("1","","");}
if (action == "France 2") {TelecomFreebox ("2","","");}
if (action == "France 3") {TelecomFreebox ("3","","");}
if (action == "Canal +" or action=="Canal") {TelecomFreebox ("4","","");}
if (action == "France 5") {TelecomFreebox ("5","","");}
if (action == "M 6") {TelecomFreebox ("6","","");}
if (action == "Arte") {TelecomFreebox ("7","","");}
if (action == "C 8") {TelecomFreebox ("8","","");}
if (action == "W 9") {TelecomFreebox ("9","","");}
if (action == "TMC") {TelecomFreebox ("1","0","");}
if (action == "TFX") {TelecomFreebox ("1","1","");}
if (mot[0] == "NRJ" || mot[1] == "12") {TelecomFreebox ("1","2","");}
if (action == "LCP") {TelecomFreebox ("1","3","");}
if (action == "France 4") {TelecomFreebox ("1","4","");}
if (action == "BFM") {TelecomFreebox ("1","5","");}
if (action == "cnews") {TelecomFreebox ("1","6","");}
if (action == "cstar") {TelecomFreebox ("1","7","");}
if (mot[0] == "France" || mot[1] == "Ô") {TelecomFreebox ("1","9","");}
if (action == "6 ter") {TelecomFreebox ("2","2","");}
if (mot[0] == "Numéro" || mot[1] == "23") {TelecomFreebox ("2","3","");}
if (action == "RMC") {TelecomFreebox ("2","4","");}
if (mot[0] == "chérie" || mot[1] == "25") {TelecomFreebox ("2","5","");}
if (action == "LCI") {TelecomFreebox ("2","6","");}
if (mot[0] == "France" || mot[1] == "Info") {TelecomFreebox ("2","7","");}
if (mot[0] == "Paris" || mot[1] == "Première") {TelecomFreebox ("2","8","");}
if (action == "RTL 9") {TelecomFreebox ("2","9","");}
if (action == "Téva") {TelecomFreebox ("3","8","");}
if (mot[0] == "AB" || mot[1] == "1") {TelecomFreebox ("3","9","");}
if (action == "Paramount") {TelecomFreebox ("5","8","");}
if (mot[0] == "planète" || mot[1] == "+") {TelecomFreebox ("5","9","");}
if (mot[0] == "National" || mot[1] == "Geographic") {TelecomFreebox ("6","0","");}
if (mot[0] == "National" || mot[1] == "Wild") {TelecomFreebox ("6","1","");}
if (mot[0] == "M6" || mot[1] == "Music") {TelecomFreebox ("6","4","");}
if (mot[0] == "NRJ" || mot[1] == "hits") {TelecomFreebox ("6","5","");}
if (mot[0] == "MTV" || mot[1] == "hits") {TelecomFreebox ("6","6","");}
if (mot[0] == "trace" || mot[1] == "urban") {TelecomFreebox ("6","7","");}
if (action == "Vivolta") {TelecomFreebox ("6","9","");}
if (action == "TV5") {TelecomFreebox ("7","0","");}
if (mot[0] == "TV" || mot[1] == "Breizh") {TelecomFreebox ("7","1","");}
if (action == "comédie") {TelecomFreebox ("8","0","");}
if (mot[0] == "polar" || mot[1] == "+") {TelecomFreebox ("8","1","");}
if (mot[0] == "Warner" || mot[1] == "TV") {TelecomFreebox ("8","2","");}
if (mot[0] == "serie" || mot[1] == "club") {TelecomFreebox ("8","3","");}
if (action == "MTV") {TelecomFreebox ("8","4","");}
if (mot[0] == "elle" || mot[1] == "girl") {TelecomFreebox ("8","5","");}
if (mot[0] == "fashion" || mot[1] == "TV") {TelecomFreebox ("2","4","1");}
if (mot[0] == "planete" || mot[1] == "CI") {TelecomFreebox ("2","0","0");}
if (mot[0] == "planete" || mot[1] == "Aventure") {TelecomFreebox ("2","0","1");}
if (action == "ushuaîa") {TelecomFreebox ("2","0","4");}
if (action == "histoire") {TelecomFreebox ("2","0","5");}
if (mot[0] == "toutes" || mot[1] == "histoire") {TelecomFreebox ("2","0","6");}
if (mot[0] == "science" || mot[1] == "vie") {TelecomFreebox ("2","0","7");}

if (mot[0] == "un" || mot[1] == "DVD"){
    TelecomFreebox ("home","","");
    delay(2000);
    TelecomFreebox ("right","","");
    delay(1000);
    TelecomFreebox ("right","","");
    delay(1000);
    TelecomFreebox ("right","","");
    delay(1000);
    TelecomFreebox ("ok","","");
    }
}//

/*** ALLUME ***/
int MotAllume(String action){

String mot[2];
    mot[0]="";
    mot[1]="";

    int index = 0;
    for( int i = 0; i < action.length(); i++ ){
        
      if( index < 2 ){// on sépare les mots reçus
        char sep = action.charAt(i);
        mot[index] += sep;

      if( sep == ' ') index++;// si il y a un espace entre
      }
    }
    
// Toutes les lumières
 if(mot[0] == "tout"){
colorWipe(strip.Color(255, 0, 0), VitesseAllume); // lampe en rouge
mySwitch.send(16762196, 24);// boule
delay(5);
mySwitch.send(16765268, 24);// lampadaire
delay(5);
mySwitch.send(16766036, 24);// guéridon
delay(5);
mySwitch.send(16766228, 24);// étoile
  }
    
// Ruban LED
 if(mot[0] == "en" || mot[1] == "rouge"){
colorWipe(strip.Color(255, 0, 0), VitesseAllume); // lampe en rouge
  }
  
    if(mot[0] == "en" || mot[1] == "vert" || mot[1] == "verre"){
colorWipe(strip.Color(0, 255, 0), VitesseAllume); // lampe en vert
  }
  
    if(mot[0] == "en" || mot[1] == "bleu"){
colorWipe(strip.Color(0, 0, 255), VitesseAllume); // lampe en bleu
  }
  
    if(mot[0] == "en" || mot[1] == "blanc"){
colorWipe(strip.Color( 255, 255, 255), VitesseAllume); // lampe en blanc
  }
  
      if(mot[0] == "ciel"){
rainbow(27); // Arc en Ciel
  }
  
/*** modules 433 mhz ***/    
  if(mot[0] == "la" || mot[1] == "cuisine"){
mySwitch.send(1975778, 24);
  }
  
  if(mot[0] == "la" || mot[1] == "boule"){// boule
mySwitch.send(16762196, 24);
  }
  
  if(mot[0] == "le" || mot[1] == "lampadaire"){
mySwitch.send(16765268, 24);
  }
  
  if(mot[0] == "le" || mot[1] == "guéridon"){
mySwitch.send(16766036, 24);
  }
  
  if(mot[0] == "la" or mot[1] == "veilleuse"){// étoile
mySwitch.send(16766228, 24);
  }

  if(mot[0] == "le" || mot[1] == "5.1"){// ampli 5.1
  transmitter.Transmit(Ampli_OnOff, sizeof(Ampli_OnOff) / sizeof(Ampli_OnOff[0]));  
  }
  
if (mot[0] == "la" || mot[1] == "télé" or mot[1] == "Freebox") {
    transmitter.Transmit(Ampli_OnOff, sizeof(Ampli_OnOff) / sizeof(Ampli_OnOff[0]));//Ampli 5.1
    TelecomFreebox ("power","","");//Freebox sur TV
    delay(1500);
    TelecomFreebox ("ok","","");
    delay(2000);
    TelecomFreebox ("0","","");// mosaique
    delay(100);
    // pour réveiller le switch HDMI
    transmitter.Transmit(SwitchHDMI2, sizeof(SwitchHDMI2) / sizeof(SwitchHDMI2[0]));// HDMI 2
    delay(300);
    transmitter.Transmit(SwitchHDMI3, sizeof(SwitchHDMI3) / sizeof(SwitchHDMI3[0]));// HDMI 3
    delay(300);
    transmitter.Transmit(SwitchHDMI1, sizeof(SwitchHDMI1) / sizeof(SwitchHDMI1[0]));// Switch HDMI sur Freebox
    }

}//FinAllume

/*** ETEINT ***/
int  MotEteint(String action){

String mot[2];
    mot[0]="";
    mot[1]="";

    int index = 0;
    for( int i = 0; i < action.length(); i++ ){
        
      if( index < 2 ){// on sépare les mots reçus
        char sep = action.charAt(i);
        mot[index] += sep;

      if( sep == ' ') index++;// si il y a un espace entre
      }
    }

    if(mot[0] == "la" || mot[1] == "lampe"){// ruban LED
colorWipe(strip.Color( 0, 0, 0), 60); // rien
  }
  
 if(mot[0] == "tout"){// Toutes les lumières
mySwitch.send(16762193, 24);// boule
delay(5);
mySwitch.send(16765265, 24);// lampadaire
delay(5);
mySwitch.send(16766033, 24);// guéridon
delay(5);
mySwitch.send(16766225, 24);// étoile
colorWipe(strip.Color(0, 0, 0), VitesseAllume); // lampe
  }  
  
  if(mot[0] == "la" || mot[1] == "cuisine"){
  mySwitch.send(1975778, 24);
  }
  
    if(mot[0] == "la" || mot[1] == "boule"){
mySwitch.send(16762193, 24);
  }
  
  if(mot[0] == "le" || mot[1] == "lampadaire"){
mySwitch.send(16765265, 24);
  }
  
  if(mot[0] == "le" || mot[1] == "guéridon"){
mySwitch.send(16766033, 24);
  }
  
  if(mot[0] == "la" or mot[1] == "veilleuse"){// étoile
mySwitch.send(16766225, 24);
  }

  if(mot[0] == "le" || mot[1] == "5.1"){// ampli 5.1
  transmitter.Transmit(Ampli_OnOff, sizeof(Ampli_OnOff) / sizeof(Ampli_OnOff[0]));
  }

  if(mot[0] == "la" || mot[1] == "télé" or mot[1] == "Freebox"){
  transmitter.Transmit(Ampli_OnOff, sizeof(Ampli_OnOff) / sizeof(Ampli_OnOff[0]));// ampli 5.1
  TelecomFreebox ("power","","");// Freebox
  }
  
}//FinEteint

/*** ON VA SE COUCHER ***/
int  EteintTout(String appareil){

transmitter.Transmit(Ampli_OnOff, sizeof(Ampli_OnOff) / sizeof(Ampli_OnOff[0]));// ampli 5.1
TelecomFreebox ("power","","");// Freebox
mySwitch.send(16762193, 24);// boule
delay(5);
mySwitch.send(16765265, 24);// lampadaire
delay(5);
mySwitch.send(16766033, 24);// guéridon
delay(5);
mySwitch.send(16766225, 24);// étoile
colorWipe(strip.Color(0, 0, 0), VitesseAllume); // lampe

}//

/*** FONCTIONS RUBAN WS2812 ***/
void colorWipe(uint32_t c, uint8_t wait) {// changement de couleurs
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

void rainbow(uint8_t wait) {// arc en ciel
  uint16_t i, j;
  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}


/*** FONCTION TELECOMMANDE FREEBOX ***/
void TelecomFreebox(String touche1, String touche2, String touche3){
  int URL1 = client.get("/pub/remote_control?code=86700567&key="+touche1);
  Particle.publish("Touche Freebox 01", String(touche1), PRIVATE);
  delay(50);
  int URL2 = client.get("/pub/remote_control?code=86700567&key="+touche2);
  Particle.publish("Touche Freebox 02", String(touche2), PRIVATE);
  delay(50);
  int URL3 = client.get("/pub/remote_control?code=86700567&key="+touche3);
  Particle.publish("Touche Freebox 03", String(touche3), PRIVATE);
}//

L’électronique

Tout est basé sur le Photon, juste à connecté le module RX433, les 2 LED infra-rouge et le condo, permettant de protéger le ruban LED.

IFTTT

Il suffira d’avoir en Trigger Google Assistant et en Action Particle.

Le code permet d’avoir 2 mots en TextFiled (la télé par exemple) mais on peut le modifier facilement.

Montage en 3D

Le Photon est placé au dessus et je me suis permis de faire un semblant de design 😉

Les fichiers 3D


Étiquettes : , ,
Copyright 2017. All rights reserved.

Ecrit 1 mai 2018 par Pit dans la catégorie "Electronique

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée.

seize − 5 =