433mhz outlet



  • I am trying to convert this code for outlet ; http://forum.mysensors.org/topic/7/controlling-blinds-com-rf-dooya-motors-with-arduino-and-vera/10 (note its using old lib)

    +vera doesn't give auto id (all other sensor like motion etc) so i made it int hey = 14; in this way i can get sketch name etc...

    my 433 on code : 1101010101011100000000110
    my 433 off code : 1101010101011100000011000

    on-off-433.png
    code txt : outlet433



  • I'm also interested in a working example to control some 240V Sockets http://www.wattsclever.com/products/easy-off-sockets

    I've found the codes to send, just need to know how to send them 🙂



  • @jribera

    Below is a simple sketch I use for controlling 433Mhz outlets (sockets) with MySensors. I am not very good at coding but this sketch worked for my setup, I assume it could be improved.

    https://codebender.cc/sketch:67827

    I created a sensor node with a nano connected to a 433Mhz transmitter which is on mains power so the sensor is always "listening". I used the 5V from the nano to power the 433 transmitter but I believe it could run off 3.3V. The node controls four cheap 433Mhz outlets. I only have four but this sketch could be expanded to control many more. These outlets do not give feedback so the sketch is somewhat simple in that regard. These outlets use the PT2262 encoder which is common but may not work with your sockets. If you have a remote with your sockets, your can take it apart to see what encoder is used.

    -Dwalt



  • @Dwalt

    Thank Dwalt, i have uploaded your sketch to one of my Nano's with a 433Mhz Transmitter and i can see it working. Ie using another Nano with a 433mhz receiver and the sample 433 receiver sketch i can see the various codes been received ie "419915".

    My problem is i don't quite understand how to update your sketch with the codes for my sockets. Using my 433 receiver nano i can see my remote sends the code 501601 to turn on socket 1. I thought i would just need to convert this to Binary, but that doesn't seem to work.

    Are you able to explain the code format for turning on/off sockets in your sketch ?

    Joseph


  • Mod

    there is also a complete library RCSwitch to work with both transmitters and receivers
    https://code.google.com/p/rc-switch/

    in my case I'm using a cheap wireless 433MHz motion sensor from my security system to drive the light too



  • @jribera How did you obtain your code (e.g."419915")? Did you use a library like RCSwitch or RemoteSwitch? If so, those libraries usually include sketches to retransmit the codes.

    My sketch above is essentially a relay sketch which creates 4 child sensors in Vera. The children show up as 4 separate on-off light switches within "Devices". For my situation, I sniffed the code with the 433 receiver hooked up to a computer running Audacity and deciphered the signal into a binary sequence. For example -> remote button #1 -"ON" = 0101000101010101001111000, repeated 6 times. This is not necessarily the code the remote is using, it is a binary representation of what the pt2262 encoder sends through the air to the receiver, which decodes it through a pt2272.

    The sketch mimics the timing and pattern of the signal by sending "highs" and "lows" of certain lengths at 433Mhz which arrive at the receiver looking similar to a signal sent from the programed remote. The sketch simply says put pin3 (the 433transmitter) to "high" then "delay" and then "low" to create the signal (static void ookPulse). The "pt2262Send" command determines whether the delay is long (500us) or short (160us) depending on whether the binary is a "1" or a "0" for each digit of the 'sniffed' binary code. The last digit is always a zero, so the pt2262send command repeats through a 16 digit code followed by an 8 digit code, adds the zero and then repeats the entire process 6 times. I should have used "uint32_t" instead of "uint16_t" and "uint8_t" for the 25digit codes. I was copying and pasting from different sources until it suddenly worked and then I didn't want to "fix" something that was working. I borrowed 'ookpulse' and 'pt2262send' from other sketches found online. I don't think it matters what they are named.

    Within "Setup" in the sketch, the node is established as a repeater node and the number of child sensors (outlets) is declared. Within "Loop", the sensor node listens for incoming commands for that node and triggers different binary codes (to be processed by the pt2262send action) for each child and whether the command is off or on (incomingLightState -> 0 or 1).

    Not the most elegant solution but it worked. I tried using some of the Libraries available from different sources and I could not get them to work with MySensors properly.

    -Dwalt



  • Thanks Dwalt, understood now. I had assumed the code i received from the rc-switch sniffer sketch, could be translated to binary and used in your sketch.

    Looks like i will need to build a different sniffer.



  • @jribera
    There are many different ways to control 433mhz devices (such as the RCSwitch and Remote Switch Libraries), mine is just one method.



  • @axillent Please can you share link of 433 motion sensor?


  • Mod

    @C.r.a.z.y. said:

    @axillent Please can you share link of 433 motion sensor?

    with pleasure
    what exactly do you need?



  • Finally managed to get this working by modifying Dwalts sketch to use the rcswitch library.

    I found this much simpler to use as it allows you to learn your existing codes using a simple RF-Sniffer sketch (Sniffer.ino) ie no need to mess around with recording signals, binary codes etc. This sketch simply displays a decimal number which you can just send back to control your devices.

    ie

    define CODE_1On 0x5FF0DC //Sniffed code converted to Hex.

    Serial.println("Turn on Socket 1");
    mySwitch.send(CODE_1On, 24); // These codes are unique to each outlet
    delay(50);

    With this working i can now safely control a number of 240V devices around the home !


  • Contest Winner

    @Dwalt

    Nice job, I want one now!

    Much easier to copy the transmission data with that sketch than the other examples here...

    To help simplify your code, you can try to add in arrays...

    int rfMessageON[4][2]=
    {
      {0b0101000101010101, 0b00110011},
      {0b0101000101010101, 0b11000011},
      {0b0101000101010111, 0b00000011},
      {0b0101000101011101, 0b00000011}
    };
    
    int rfMessageOFF[4][2]= 
    {
      {0b0101000101010101, 0b00111100},
      {0b0101000101010101, 0b11001100},
      {0b0101000101010111, 0b00001100},
      {0b0101000101011101, 0b00001100}
    };
    

    to make a much simpler function...

    void loop() 
    {
      gw.process();
    }
    //
    void incomingMessage(const MyMessage &message) 
    {
      if (message.type==V_LIGHT) 
      {
        Serial.print("Outlet #: ");
        Serial.println(message.sensor);
        Serial.print("Command: ");
        Serial.println(message.getBool());
        pt2262Send(message.getBool()? rfMessageON[message.sensor - 1][0],rfMessageON[message.sensor - 1][1]: rfMessageOFF[message.sensor - 1][0],rfMessageOFF[message.sensor - 1][1]);
      }
      delay(50);
    }
    

    (not tested)



  • @axillent Motion sensor ; brand, model, which chip in it?

    I have an remote like this (attached) and it didnt work with RC-Switch. (RC-Switch works with SC5262 / SC5272, HX2262 / HX2272, PT2262 / PT2272, EV1527, RT1527, FP1527 or HS1527 chipsets)

    If my remote is working with other chipset, how can i read and transmit it?

    How can i find this remote's chipset?
    ----PIC16F630 ---update http://ww1.microchip.com/downloads/en/devicedoc/40039f.pdf

    image1.JPG



  • @jribera mind posting your completed code?



  • @dayve218 said:

    @jribera mind posting your completed code?

    nevermind, i figured it out!


  • Mod

    @C.r.a.z.y. my sensors are none brand)) all using PT2262
    was purchased from here http://ru.aliexpress.com/item/-/1953282784.html?recommendVersion=1
    I have PIR sensors, door sensors, water leakage and gas leakage sensors.
    I also have a remote similar to your.

    Remote is easily recognized using radio 433MHz receiver connected to arduino and RCSwitch library

    It is also a plan to create a gateway from 433MHZ to NRF24 network - this can help me to build vera3 automation using a security sensors without purchasing z-wave or building mysensors sensors



  • @axillent Thank you. Do you have dip switches in your sensors?

    I found a comparasion table maybe this could help people like me;

    http://www.hkvstar.com/technology-news/the-difference-between-fixed-code-pt2262-and-learning-code-ev1527.html

    If my remote is not a fixed code, how can i read and transmit it?


  • Mod

    @C.r.a.z.y. some sensors do have dip switches, some have preprogrammed radio code

    if you have RF receiver you can try to get a code from your remote using example receiver sketch from RCSwitch library. I build a custom arduino with RF receiver and a button which I use to program the first received code into arduino EEPROM. Later this code is used to identify which sensor should light up my leds.
    IMG_1880.JPG



  • @axillent OK i understand fixed codes are fine with RCSwitch.

    How can i transmit this data ?

    1100 0011 0010 0010 0011 0000 1100 1000 1000
    1100 0011 0001 0010 0011 0000 1100 0100 1000


  • Mod

    @C.r.a.z.y. Open any transmitting example from RCSwitch
    I never did it but I think send() function is designed for this
    https://code.google.com/p/rc-switch/wiki/HowTo_Send?tm=6



  • @axillent Thank you i know you are very helpful. I tried to copy my remote to an universal remote learner(which has no name chipset) but it didnt copy. It is hard to understand and solve for a newbie.

    I simply tried to send 10101010codes with this sketch https://code.google.com/p/rc-switch/wiki/HowTo_Send?tm=6 and didnt work.

    Something interesting i found while tranmitting,
    If i remove the delay () than signal is always sent. I made a jammer! 🙂 Any of my 433 remotes didnt work!

    I want to learn if any universal remote learner with EV1527 Chipset works with RCSwitch?
    My plan is to copy some remote codes to EV1527 universal remote and read the code from serial with RCSwitch-rfSniffer.

    Now i will try IR SENDER-RECEIVER http://www.mysensors.org/build/ir maybe i can get new ideas for 433mhz things..



  • @jribera Been try to get this happening myself. Can you provide the sketch you ended up using to get this happening so I can try it. I know what all my codes are, just need to get a sketch happening to interface back to my controller (Domoticz Serial)

    Cheers



  • This is the sketch i'm using for controlling a number of sockets around the house.

    /*  RF433Mhz Transmitter node:
        This sketch allows On-Off-Keying (OOK) control of four 433Mhz relay outlets
        which utilize the common PT2262 encoding chip for signal transmission. The sketch could
        be easily expanded to include additional outlets.  The sensor node consists of a nano 
        connected to a NRF24L01 and a 433Mhz transmitter connected to pin 3, 5V and Gnd.  The 
        transmitter can run off of 3.3V as well. 
        
        The sketch is based on the MySensors project (http://www.mysensors.org). 
        Submitted by Dwalt.
    */ 
    
    //  Include related libraries
    #include <MySensor.h>
    #include <SPI.h>  
    #include <RF24.h>
    #include <RCSwitch.h>
    
    //  Define Constants
    #define RF433_CHILD_ID 0
    #define NUMBER_OF_OUTLETS 4 // Each outlet will have 2 OOK codes
    //#define SEND_DATA 3
    
    #define CODE_1On 6287582
    #define CODE_1Off 6287574
    #define CODE_2On 6287580
    #define CODE_2Off 6287572
    #define CODE_3On 6287578
    #define CODE_3Off 6287570
    #define CODE_4On 6287577
    #define CODE_4Off 6287569
    
    MySensor gw;
    
    RCSwitch mySwitch = RCSwitch();
    
    void setup() 
    {
      
    
    mySwitch.enableTransmit(3); 
      
     Serial.begin(115200); // Not sure why this was included
    
     //  The node is mains powered, so why not make it a repeater.
     gw.begin(incomingMessage, AUTO, true);
     
     // Send the sketch version information to gateway
     gw.sendSketchInfo("RF433", "1.1");
     
     // Register outlets to gw (they will be created as child devices)
     for(int i=0; i<NUMBER_OF_OUTLETS;i++) {
       gw.present(i+1, S_LIGHT);
    
     }
        
    }
    
    void loop() {
      gw.process();
    }
      void incomingMessage(const MyMessage &message) {
      
      if (message.type==V_LIGHT) {
      int incomingLightState =  message.getBool(); 
      int incomingOutlet = message.sensor;
      
      Serial.print("Outlet #: ");
      Serial.println(message.sensor);
      Serial.print("Command: ");
      Serial.println(message.getBool());
     
     if (incomingOutlet==1) {
     if (incomingLightState==1) {
        // Turn on  socket 1
        Serial.println("Turn on Socket 1");
     mySwitch.send(CODE_1On, 24); // These codes are unique to each outlet
     delay(50); 
     }
     if (incomingLightState==0)  {
        // Turn off socket 1
     Serial.println("Turn off Socket 1");
    mySwitch.send(CODE_1Off, 24);
    delay(50); 
     }
     }
     if (incomingOutlet==2) {
     if (incomingLightState==1) {
        // Turn on  socket 2
        Serial.println("Turn on Socket 2");
    mySwitch.send(CODE_2On, 24);
     delay(50); 
     }
     if (incomingLightState==0)  {
        // Turn off socket 2
     Serial.println("Turn off Socket 2");
    mySwitch.send(CODE_2Off, 24);
    delay(50); 
     }
     }
     if (incomingOutlet==3) {
     if (incomingLightState==1) {
        // Turn on  socket 3
        Serial.println("Turn on Socket 3");
    mySwitch.send(CODE_3On, 24);
     delay(50); 
     }
     if (incomingLightState==0)  {
        // Turn off socket 3
     Serial.println("Turn off Socket 3");
    mySwitch.send(CODE_3Off, 24);
    delay(50); 
     }
     }
     if (incomingOutlet==4) {
     if (incomingLightState==1) {
        // Turn on  socket 4
        Serial.println("Turn on Socket 4");
     mySwitch.send(CODE_4On, 24);
     delay(50); 
     }
     if (incomingLightState==0)  {
        // Turn off socket 4
     Serial.println("Turn off Socket 4");
    mySwitch.send(CODE_4Off, 24);
    delay(50); 
     }
     }
      }
     delay(50);
     }    
        
       
        
    
    
    
    
    


  • @jribera Your sketch works perfectly 🙂
    I am trying to add also 433 receiver to allow domoticz update states of the switches is the Socket is switched on or off by remote control. Does anybody know how to do that? After receiving certain code change the state of the corresponding socket.
    treb0r



  • @treb0r said:

    I am trying to add also 433 receiver to allow domoticz update states of the switches is the Socket is switched on or off by remote control. Does anybody know how to do that? After receiving certain code change the state of the corresponding socket.
    treb0r

    Im an just trying to do this (also with domoticz) 😉

    Here is my first try of the function using RCSwitch.h:

    /****************************************
    * Analyse the Radio traffic and set the states
    ****************************************/
    void readRadio()
    {
    	if (mySwitch.available())
    	{
    		int value = mySwitch.getReceivedValue();
    
    		if (value == 0)
    		{
    			#ifdef DEBUG
    			Serial.print("Unknown encoding");
    			#endif
    		}
    		else
    		{
    			led(false,4,150);
    			#ifdef DEBUG
    			Serial.print("Received ");
    			Serial.print( mySwitch.getReceivedValue() );
    			Serial.print(" / ");
    			Serial.print( mySwitch.getReceivedBitlength() );
    			Serial.print("bit ");
    			Serial.print("Protocol: ");
    			Serial.println( mySwitch.getReceivedProtocol() );
    			#endif
    			
    			if (value == 4373) //Stehlampe ON
    			{
    				#ifdef DEBUG
    				Serial.println("Stehlampe ON detected");
    				#endif
    			}
    			else if (value == 4372 ) //Stehlampe OFF
    			{
    				#ifdef DEBUG
    				Serial.println("Stehlampe OFF detected");
    				#endif
    				resend((msgLight1.set(0)),m_repeat);
    			}
    			else if (value == 1048597 ) //Vitrine ON
    			{
    				#ifdef DEBUG
    				Serial.println("Vitrine ON detected");
    				#endif
    				resend((msgLight2.set(1)),m_repeat);
    			}
    			else if (value == 1048596 ) //Vitrine OFF
    			{
    				#ifdef DEBUG
    				Serial.println("Vitrine OFF detected");
    				#endif
    				resend((msgLight2.set(0)),m_repeat);
    			}
    			mySwitch.resetAvailable();
    		}
    	}
    }


  • @jribera What version of mysensors was this coded for? I'm having issues building this on 1.4 for some reason.



  • @justinthegeek

    Also 1.4


Log in to reply
 

Suggested Topics

  • 6
  • 4
  • 3
  • 4
  • 4
  • 5

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts