skagmo
Posts: 3
Joined: Sat Dec 22, 2012 8:41 am

PiHAT - Rasberry Pi Home Automation Transmitter

Sat Dec 22, 2012 8:49 am

Based on the brilliant work on the **** project, I decided to use the fractional divider to control remote power switches operating at 433.92 MHz. A long story short; it worked! As of now it is limited to controlling Nexa-remotes (which is commonly available at least here in Scandinavia).

Source code, compiled binary and instructions: http://www.skagmo.com/page.php?p=projects/22_pihat

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Sat Dec 22, 2012 4:04 pm

so the pi could turn itself off?

User avatar
cyrano
Posts: 714
Joined: Wed Dec 05, 2012 11:48 pm
Location: Belgium

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Sun Dec 23, 2012 1:35 am

Nice! Other stuff worth reading too! I really like your groundstation.

skagmo
Posts: 3
Joined: Sat Dec 22, 2012 8:41 am

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Mon Dec 24, 2012 10:49 am

pygmy_giant wrote:so the pi could turn itself off?
While you can, I don't really see why you would do that.
The wireless power switches can be used for anything: A lamp, an oven etc.
cyrano wrote:Nice! Other stuff worth reading too! I really like your groundstation.
Thanks!

leonardo
Posts: 9
Joined: Sun Dec 30, 2012 3:30 pm
Location: Italy, not my fault, I wasn't able to deceide where to born

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Sun Dec 30, 2012 4:39 pm

Nice hack Skagmo!
Sadly I don't have any Nexa-remote but I'm trying to play with some similar items.
At this point I'm guessing is there any way to READ 433 MHz signal in a similar way?

skagmo
Posts: 3
Joined: Sat Dec 22, 2012 8:41 am

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Tue Jan 08, 2013 9:53 am

leonardo wrote:Nice hack Skagmo!
Sadly I don't have any Nexa-remote but I'm trying to play with some similar items.
At this point I'm guessing is there any way to READ 433 MHz signal in a similar way?
Thank you!

RF-reception is not that easy to achieve, and a (bad) ASK-receiver would require 4-5 components at least.

leonardo
Posts: 9
Joined: Sun Dec 30, 2012 3:30 pm
Location: Italy, not my fault, I wasn't able to deceide where to born

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Tue Jan 08, 2013 8:32 pm

Yes, I find the answer trying to read the code. If I'm not wrong, you create something similar a oscillator at 433MHz without having the oscillator! That's possible to "send" signals, but to receive we must have all the circuit!

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Tue Jan 08, 2013 8:48 pm

by skagmo » 24 Dec 2012 10:49
pygmy_giant wrote:so the pi could turn itself off?
While you can, I don't really see why you would do that.
The wireless power switches can be used for anything: A lamp, an oven etc.
I thought maybe it could be useful if you had to leave the Pi running for a long indeterminate ammount of time and wanted it to power down afterwards.

I had this situation a few months ago when I was calculating permutations - I new it was going to take a long time (over 24 hours) but I did not know how long, and I wanted to get on with my life without leaving appliances switched on unnecessarily.

Impressive work by the way.

necc
Posts: 25
Joined: Thu Aug 30, 2012 10:55 pm

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Wed Jan 09, 2013 2:55 pm

pygmy_giant wrote: I thought maybe it could be useful if you had to leave the Pi running for a long indeterminate ammount of time and wanted it to power down afterwards..
Yup, much easier to build an rf transmitter paired with a RF-enabled socket than script "shutdown -h now " :D

ant_thomas
Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Wed Jan 09, 2013 3:14 pm

skagmo wrote:Based on the brilliant work on the **** project, I decided to use the fractional divider to control remote power switches operating at 433.92 MHz. A long story short; it worked! As of now it is limited to controlling Nexa-remotes (which is commonly available at least here in Scandinavia).

Source code, compiled binary and instructions: http://www.skagmo.com/page.php?p=projects/22_pihat
This looks very interesting. I might look into it with some RF sockets I have. No idea yet what frequency they run on, or what signal they require, but they do have a similar "long press" for pairing system to pair with the remote.

necc
Posts: 25
Joined: Thu Aug 30, 2012 10:55 pm

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Wed Jan 09, 2013 3:18 pm

I've successfully utilised rfxtrx433 to communicate with such devices. It provides a usb-serial interface, which is relatively simple to code with perl and supports a bunch of various protocols.

ant_thomas
Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Wed Jan 09, 2013 6:03 pm

skagmo wrote:Based on the brilliant work on the project, I decided to use the fractional divider to control remote power switches operating at 433.92 MHz. A long story short; it worked! As of now it is limited to controlling Nexa-remotes (which is commonly available at least here in Scandinavia).

Source code, compiled binary and instructions: http://www.skagmo.com/page.php?p=projects/22_pihat
I've tried it with my "Status" Remote Sockets. They too run on 433.92MHz but it doesn't seem to work.

I've got a socket which is "1" on my remote and I've tried...

Code: Select all

sudo ./pihat --id=1 --channel=0 --state=0
sudo ./pihat --id=1 --channel=1 --state=0
sudo ./pihat --id=1 --channel=2 --state=0
sudo ./pihat --id=1 --channel=3 --state=0
sudo ./pihat --id=1 --channel=4 --state=0
sudo ./pihat --id=1 --channel=5 --state=0
sudo ./pihat --id=1 --channel=6 --state=0
sudo ./pihat --id=1 --channel=7 --state=0
sudo ./pihat --id=1 --channel=8 --state=0
sudo ./pihat --id=1 --channel=9 --state=0
sudo ./pihat --id=1 --channel=10 --state=0
sudo ./pihat --id=1 --channel=11 --state=0
sudo ./pihat --id=1 --channel=12 --state=0
sudo ./pihat --id=1 --channel=13 --state=0
sudo ./pihat --id=1 --channel=14 --state=0
sudo ./pihat --id=1 --channel=15 --state=0
Do you have any idea how I can find out what parameters to change in the code to recompile? Or whether you'd like to add the required bits (if I can find them) to the existing code since I can see you've added a Brand argument.

ant_thomas
Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Wed Jan 09, 2013 6:33 pm

This thread might be helpful....

http://www.picaxeforum.co.uk/showthread ... 850d92f87e

More so this post.....
Decoding the RCT-08 remote using a standard 433MHz receiver module and 20X2 :-)

Typical output ...

0001 <0110 0000 0111 1011> <1000> 0 Remote=$607B All Off
0001 <0110 0000 0111 1011> <1111> 0 Remote=$607B 1 On
0001 <0110 0000 0111 1011> <1111> 0 Remote=$607B 1 On
0001 <0110 0000 0111 1011> <0111> 0 Remote=$607B 1 Off

0001 <0011 1110 1111 0000> <1000> 0 Remote=$3EF0 All Off
0001 <0011 1110 1111 0000> <1000> 0 Remote=$3EF0 All Off

s7mx1
Posts: 78
Joined: Fri Sep 30, 2011 9:28 am

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Thu Jan 10, 2013 2:17 pm

@ant_thomas

Can you download 20X2-Morissons.txt and 20X2-Morrisons-Tx.txt? I don't have permissions to download them.

It does seem to be easy to implement the status remote protocol according to the link you posted, unless there are preamle and postamble like nexa remote.

I will try to write something in a few days time.

s7mx1
Posts: 78
Joined: Fri Sep 30, 2011 9:28 am

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Thu Jan 10, 2013 3:35 pm

I did some quick code and you can download the modified version (for status remote) here

https://github.com/s7mx1/pihat/raw/master/pihat

Usage is here

https://github.com/s7mx1/pihat

I have not tested it personally so it may or may not work and I am not responsible for any damage it may cause.

ant_thomas
Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Thu Jan 10, 2013 4:20 pm

s7mx1 wrote:I did some quick code and you can download the modified version (for status remote) here

https://github.com/s7mx1/pihat/raw/master/pihat

Usage is here

https://github.com/s7mx1/pihat

I have not tested it personally so it may or may not work and I am not responsible for any damage it may cause.
Thanks for these, I'll give them a go later.

The Status remotes are a fairly common cheap remote socket in the UK so if the program does work with them you might have some very happy users on here!

I wanted to provide those .txt files from the other forum but I'm still waiting for my account to be approved so I can access the attachments. Once it is I'll get them to you.

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Thu Jan 10, 2013 6:30 pm

s7mx1 wrote:I did some quick code and you can download the modified version (for status remote) here

https://github.com/s7mx1/pihat/raw/master/pihat

Usage is here

https://github.com/s7mx1/pihat

I have not tested it personally so it may or may not work and I am not responsible for any damage it may cause.
I just downloaded the binary and it won't run: -bash: ./pihat: cannot execute binary file according to "file" it appears to be an x86 not ARM executable.
[email protected]:~# file pihat
pihat: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=0xf6401296fea2f19fcf49bd0830125d15ce6804c1, stripped

Am I doing something wrong here??

Richard S.

ant_thomas
Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Thu Jan 10, 2013 6:50 pm

redhawk wrote:I just downloaded the binary and it won't run: -bash: ./pihat: cannot execute binary file according to "file" it appears to be an x86 not ARM executable.
[email protected]:~# file pihat
pihat: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=0xf6401296fea2f19fcf49bd0830125d15ce6804c1, stripped

Am I doing something wrong here??

Richard S.
It didn't work for me either. So did

git clone https://github.com/s7mx1/pihat.git
cd pihat
make

then ./pihat --id=0 --channel=7 --state=0

but it didn't turn anything on or off. I'm going to try a couple of other things first!

...edit - tried to pair and that hasn't worked either :(

ant_thomas
Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Thu Jan 10, 2013 7:06 pm

Got the files....

https://dl.dropbox.com/u/14641356/rpi/2 ... issons.txt

Code: Select all

#Picaxe 20X2
#No_Table
#No_Data
#Terminal 38400

Symbol DATA_PIN       = pinB.0 ' HINT1 - Received from 433MHz module

Symbol dataStream.lsw = w0     ' b1:b0
Symbol dataStream.msw = w1     ' b3:b2
Symbol dataLast.lsw   = w2     ' b5:b4
Symbol dataLast.msw   = w3     ' b7:b6
Symbol dataAvailable  = b8
Symbol hexBits        = b9

SetFreq M32

HIntSetup %00100010
Do
  Gosub InterruptEnable
  Do
    dataAvailable = 1
    Pause 12                   ' 3ms @ 32MHz
  Loop Until dataAvailable = 1
  dataStream.msw = 0
  dataStream.lsw = 0
  Do
    Do
      dataAvailable = 1
      Pause 12                 ' 3ms @ 32MHz
    Loop Until dataAvailable = 1
  Loop until dataStream.lsw > 1
  SetIntFlags OFF
  If bit24=0 And bit23=0 And bit22=0 And bit21=1 And bit0=0 Then
    If dataStream.msw = dataLast.msw And dataStream.lsw = dataLast.lsw Then 
      SerTxd( #bit24, #bit23, #bit22, #bit21, " <"   ) 
      SerTxd( #bit20, #bit19, #bit18, #bit17, " "    ) 
      SerTxd( #bit16, #bit15, #bit14, #bit13, " "    ) 
      SerTxd( #bit12, #bit11, #bit10, #bit9,  " "    ) 
      SerTxd( #bit8,  #bit7,  #bit6,  #bit5,  "> <"  ) 
      SerTxd( #bit4,  #bit3,  #bit2,  #bit1,  "> "   )
      SerTxd( #bit0                                  )
      dataStream.lsw = dataStream.lsw >> 1
      bit15 = bit16
      SerTxd( 9,"Remote=$" )
      hexBits = dataStream.msw >> 1  : Gosub ShowHex
      hexBits = dataStream.lsw >> 12 : Gosub ShowHex
      hexBits = dataStream.lsw >> 8  : Gosub ShowHex
      hexBits = dataStream.lsw >> 4  : Gosub ShowHex
      SerTxd( "  " )
      hexBits = dataStream.lsw & $F
      Select Case hexBits

        Case %1000 : SerTxd( "All Off" )

        Case %0111 : SerTxd( "1 Off"   )
        Case %1111 : SerTxd( "1 On"    )

        Case %0011 : SerTxd( "2 Off"   )
        Case %1011 : SerTxd( "2 On"    )

        Case %0101 : SerTxd( "3 Off"   )
        Case %1101 : SerTxd( "3 On"    )

        Case %0110 : SerTxd( "4 Off"   )
        Case %1110 : SerTxd( "4 On"    )

        Else       : SerTxd( "?"       )
      End Select
      SerTxd( CR, LF )
    End If
  End If
  dataLast.msw = dataStream.msw
  dataLast.lsw = dataStream.lsw
Loop

ShowHex:
  hexBits = hexBits & $0F + "0"
  If hexBits > "9" Then : hexBits = hexBits + 7 : End If
  SerTxd( hexBits )
  Return

Interrupt:
  PauseUs 90 ' ~300us @ 32MHz
  dataStream.msw = dataStream.msw << 1 | bit15
  dataStream.lsw = dataStream.lsw << 1 | DATA_PIN
  dataAvailable = 0

InterruptEnable:
  hInt1Flag = 0
  SetIntFlags %00000010, %00000010
  Return


https://dl.dropbox.com/u/14641356/rpi/2 ... ons-Tx.txt

Code: Select all

#Picaxe 20X2
#No_Table
#No_Data

Symbol  TX              = C.0

Symbol ALL_OFF          = %1000
Symbol OFF_1            = %0111
Symbol ON_1             = %1111
Symbol OFF_2            = %0011
Symbol ON_2             = %1011
Symbol OFF_3            = %0101
Symbol ON_3             = %1101
Symbol OFF_4            = %0110
Symbol ON_5             = %1110

Symbol  outputBits.lsw  = w0 ' b1:b0
Symbol  outputBits.msw  = w1 ' b3:b2
Symbol  dataStream.lsw  = w2 ' b5:b4
Symbol  dataStream.msw  = w3 ; b7:b6
Symbol  shiftData       = w4 ' b9:b8
Symbol  remoteId        = w5 ' b11:b10
Symbol  keyPress        = b12
Symbol  shiftBits       = b13
Symbol  alignLeftShift  = b14
Symbol  packetCount     = b15
Symbol  bitCount        = b16

PowerOnReset:
  SetFreq M32
  Low TX
  Goto MainLoop

SendOutputBits:
  For bitCount = 0 To 24
    If bit24 = 0 Then
      High TX
      PauseUs 70
      Low TX
      PauseUs 80
      outputBits.msw = outputBits.msw << 1 | bit15
      outputBits.lsw = outputBits.lsw << 1
    Else
      High TX
      PauseUs 215
      outputBits.msw = outputBits.msw << 1 | bit15
      outputBits.lsw = outputBits.lsw << 1
      Low TX
    End If
    Next
  Return

MainLoop:
  Do

    Pause 8000

    remoteId = $3EF0
    keyPress = ON_1
    Gosub SendCommand

    Pause 8000

    remoteId = $3EF0
    keyPress = ON_2
    Gosub SendCommand

    Pause 8000

    remoteId = $3EF0
    keyPress = OFF_1
    Gosub SendCommand


    Pause 8000

    remoteId = $3EF0
    keyPress = OFF_2
    Gosub SendCommand

  Loop

SendCommand:
  shiftData = %0001
  shiftBits = 4
  Gosub Shift
  shiftData = remoteId
  shiftBits = 16
  Gosub Shift
  shiftData = keyPress
  shiftBits = 4
  Gosub Shift
  shiftData = %0
  shiftBits = 1
  Gosub Shift
  For packetCount = 1 To 10
    outputBits.lsw = dataStream.lsw
    outputBits.msw = dataStream.msw
    Gosub SendOutputBits
    Pause 30
  Next
  Return

Shift:
  alignLeftShift = 16 - shiftBits
  shiftData = shiftData << alignLeftShift
  Do
    dataStream.msw = dataStream.msw << 1
    If dataStream.lsw >= $8000 Then
      dataStream.msw = dataStream.msw | 1
    End If
    dataStream.lsw = dataStream.lsw << 1
    If shiftData >= $8000 Then
      dataStream.lsw = dataStream.lsw | 1
    End If
    shiftData = shiftData << 1
    shiftBits = shiftBits - 1
  Loop While shiftBits > 0 
  Return
  
Edit - I think this line...
Symbol ON_5 = %1110
Should be
Symbol ON_4 = %1110

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Thu Jan 10, 2013 7:26 pm

There's a fault in the code somewhere it's not accepting the --brand parameter.
A work around: edit main.c goto line 119 and change BRAND_NEXA to BRAND_STATUS
then make and it should work.

Richard S.

ant_thomas
Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Thu Jan 10, 2013 7:32 pm

redhawk wrote:There's a fault in the code somewhere it's not accepting the --brand parameter.
A work around: edit main.c goto line 119 and change BRAND_NEXA to BRAND_STATUS
then make and it should work.

Richard S.
Thanks.

Doesn't seem to work. It's not pairing. Hopefully someone else can try too, might just be me!

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Thu Jan 10, 2013 7:42 pm

I can confirm it does work with Status remote switches (ones sold by Asda in 3 packs).

Do you have an antenna wire attached to "GPIO 4" pin?? without this your TX range is approximately 10cm.
http://elinux.org/RPi_Low-level_periphe ... .28GPIO.29
For the best range at 443.92MHz use an antenna wire of approximately 6 1/2 inches.

Richard S.

ant_thomas
Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Thu Jan 10, 2013 7:55 pm

redhawk wrote:I can confirm it does work with Status remote switches (ones sold by Asda in 3 packs).

Do you have an antenna wire attached to "GPIO 4" pin?? without this your TX range is approximately 10cm.
http://elinux.org/RPi_Low-level_periphe ... .28GPIO.29
For the best range at 443.92MHz use an antenna wire of approximately 6 1/2 inches.

Richard S.
I did have a cable plugged in, but unplugged and replugged and it's working now.

Thanks, it's appreciated!

ant_thomas
Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Thu Jan 10, 2013 7:57 pm

One more question.

Is it possible to find out the id of my actual remote without trying 0-65535?

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: PiHAT - Rasberry Pi Home Automation Transmitter

Thu Jan 10, 2013 8:09 pm

I was thinking the same thing myself so I'll let you know if I have cracked my remote ID.
The transmitter uses ook encoding (on off keying) so basically you'll have a 443.92MHz carrier for a set duration and then a set duration of no TX carrier.
These pulses can be detected by placing an FM radio next to the remote all you have to do is record the audio and interpret the pulses back to data.
By pressing buttons on the remote and comparing the pulses generated by the Pi application it should be possible to determine the remote control ID.

Richard S.

Return to “Automation, sensing and robotics”