Classic Energenie support via 433MHz

Tags: #<Tag:0x00007f3f12da0bf8>

For a while now the Energenie range of products have relied on 433MHz transmissions to control them. They offer the ‘pi-mote’ addon for Raspberry Pis too, in order for homebrew hackers to control them.

I understand the new ‘Mi-Home’ range requires a cloud-based API, but this is separate to the original Energenie range.

It would be great to have support for the RF version over the RFXCom hub. There is already support in RFXCom for this device, under the Lighting1 category. http://www.rfxcom.com/WebRoot/StoreNL2/Shops/78165469/MediaGallery/Downloads/RFXtrx_User_Guide.pdf

In addition, Domoticz seems to classify energenie and energenie5 separately, within Lighting1 - so I’m not sure if there’s protocol differences or somesuch. This may be relevant https://github.com/domoticz/domoticz/search?p=1&q=energenie&utf8=✓

As a new user I can only put 2 links in this post… more to follow :slight_smile:

The Pi-Mote Raspberry Pi board https://energenie4u.co.uk/catalogue/product/ENER314

The 4 gang socket I have https://energenie4u.co.uk/catalogue/product/ENER010

The entire Mi-Home range can be controlled with the two way Pi-mote, not just the switches. I have my Pi-mote controlling my Energenie trvs as well as some wall plugs using my MQTT driver

I’m not too sure of the capabilities of the RFXCom hub, but the MiHome range but it needs to be able to use FSK modulation to communicate with the new MiHome protocol (for controlling trvs and other devices with two way communication).

oh that’s even better then. A wider range of kit to control, and locally too :slight_smile:

The RFXCom can certainly do FSK, and probably by extension supports the OpenThings protocol. Hass supports the RFXCom, but I have no idea where to even start extending the rfxcom hub feature in Hass in order to speak Openthings!

Hi all.

I have these energenie sockets too and want to control them via home assistant.

I have them setup with the PiMote on the same Pi as the Home Assistant.

This is the code that works on the Pi with Python.

Im trying to create 8 py files to control on and off for each of the 4 sockets and control them with HA.

Im not having alot of success in stripping out the text needed to just turn one socket on or off.

Anyone done this or be able to give me a bit of help ?

Thanks

#import the required modules
import RPi.GPIO as GPIO
import time

set the pins numbering mode

GPIO.setmode(GPIO.BOARD)

Select the GPIO pins used for the encoder K0-K3 data inputs

GPIO.setup(11, GPIO.OUT)
GPIO.setup(15, GPIO.OUT)
GPIO.setup(16, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)

Select the signal to select ASK/FSK

GPIO.setup(18, GPIO.OUT)

Select the signal used to enable/disable the modulator

GPIO.setup(22, GPIO.OUT)

Disable the modulator by setting CE pin lo

GPIO.output (22, False)

Set the modulator to ASK for On Off Keying

by setting MODSEL pin lo

GPIO.output (18, False)

Initialise K0-K3 inputs of the encoder to 0000

GPIO.output (11, False)
GPIO.output (15, False)
GPIO.output (16, False)
GPIO.output (13, False)

The On/Off code pairs correspond to the hand controller codes.

True = ‘1’, False =‘0’

print "OUT OF THE BOX: Plug the Pi Transmitter board into the Raspberry Pi"
print "GPIO pin-header ensuring correct polarity and pin alignment."
print ""
print "The sockets will need to be inserted into separate mains wall sockets."
print "with a physical separation of at least 2 metres to ensure they don’t"
print "interfere with each other. Do not put into a single extension lead."
print ""
print "For proper set up the sockets should be in their factory state with"
print "the red led flashing at 1 second intervals. If this is not the case for"
print "either socket, press and hold the green button on the front of the unit"
print "for 5 seconds or more until the red light flashes slowly."
print ""
print "A socket in learning mode will be listening for a control code to be"
print "sent from a transmitter. A socket can pair with up to 2 transmitters"
print "and will accept the following code pairs"
print ""
print "0011 and 1011 all sockets ON and OFF"
print "1111 and 0111 socket 1 ON and OFF"
print "1110 and 0110 socket 2 ON and OFF"
print "1101 and 0101 socket 3 ON and OFF"
print "1100 and 0100 socket 4 ON and OFF"
print ""
print "A socket in learning mode should accept the first code it receives"
print "If you wish the sockets to react to different codes, plug in and"
print "program first one socket then the other using this program."
print ""
print "When the code is accepted you will see the red lamp on the socket"
print "flash quickly then extinguish"
print ""
print "The program will now loop around sending codes as follows when you"
print "hit a key:"
print "socket 1 on"
print "socket 1 off"
print "socket 2 on"
print "socket 2 off"
print "all sockets on"
print "all sockets off"
print "Hit CTL C for a clean exit"
try:
# We will just loop round switching the units on and off
while True:
raw_input(‘hit return key to send socket 1 ON code’)
# Set K0-K3
print "sending code 1111 socket 1 on"
GPIO.output (11, True)
GPIO.output (15, True)
GPIO.output (16, True)
GPIO.output (13, True)
# let it settle, encoder requires this
time.sleep(0.1)
# Enable the modulator
GPIO.output (22, True)
# keep enabled for a period
time.sleep(0.25)
# Disable the modulator
GPIO.output (22, False)

	raw_input('hit return key to send socket 1 OFF code')
	# Set K0-K3
	print "sending code 0111 Socket 1 off"
	GPIO.output (11, True)
	GPIO.output (15, True)
	GPIO.output (16, True)
	GPIO.output (13, False)
	# let it settle, encoder requires this
	time.sleep(0.1)
	# Enable the modulator
	GPIO.output (22, True)
	# keep enabled for a period
	time.sleep(0.25)
	# Disable the modulator
	GPIO.output (22, False)

	raw_input('hit return key to send socket 2 ON code')
	# Set K0-K3
	print "sending code 1110 socket 2 on"
	GPIO.output (11, False)
	GPIO.output (15, True)
	GPIO.output (16, True)
	GPIO.output (13, True)
	# let it settle, encoder requires this
	time.sleep(0.1)	
	# Enable the modulator
	GPIO.output (22, True)
	# keep enabled for a period
	time.sleep(0.25)
	# Disable the modulator
	GPIO.output (22, False)

	raw_input('hit return key to send socket 2 OFF code')
	# Set K0-K3
	print "sending code 0110 socket 2 off"
	GPIO.output (11, False)
	GPIO.output (15, True)
	GPIO.output (16, True)
	GPIO.output (13, False)
	# let it settle, encoder requires this
	time.sleep(0.1)
	# Enable the modulator
	GPIO.output (22, True)
	# keep enabled for a period
	time.sleep(0.25)
	# Disable the modulator
	GPIO.output (22, False)

	raw_input('hit return key to send ALL ON code')
	# Set K0-K3
	print "sending code 1011 ALL on"
	GPIO.output (11, True)
	GPIO.output (15, True)
	GPIO.output (16, False)
	GPIO.output (13, True)
	# let it settle, encoder requires this
	time.sleep(0.1)
	# Enable the modulator
	GPIO.output (22, True)
	# keep enabled for a period
	time.sleep(0.25)
	# Disable the modulator
	GPIO.output (22, False)

	raw_input('hit return key to send ALL OFF code')
	# Set K0-K3
	print "sending code 0011 All off"
	GPIO.output (11, True)
	GPIO.output (15, True)
	GPIO.output (16, False)
	GPIO.output (13, False)
	# let it settle, encoder requires this
	time.sleep(0.1)	
	# Enable the modulator
	GPIO.output (22, True)
	# keep enabled for a period
	time.sleep(0.25)
	# Disable the modulator
	GPIO.output (22, False)

Clean up the GPIOs for next time

except KeyboardInterrupt:
GPIO.cleanup()

UPDATE -

Found an easier way online to control one socket in a py file.

from energenie import switch_on, switch_off
from time import sleep

turn a plug socket on Number 1

switch_on(4)

You can probably control this board from HA using the GPIO component, without any python scripts.

thanks for the reply @gpbenton.

The issue is that Im using this board on the PI to talk to Energenie sockets.

I tried using GPIO app on phone and none of the GPIO triggered any of the sockets.

They work fine on PY so for now I will stick with that.

The issue I have now is that I cant get the command_line to work in the configuration.yaml.

I started a new thread here for that one…

I made a little API today for my Energenie plugs which I think might suit you :slight_smile:

Copy the above file to the Raspberry Pi that controls the plugs.

You might need to install flask - sudo pip install flask

Then just run the API in the background on the Pi, for example:

sudo python energenie-pi-api.py &

Over in Home Assistant, I have these in my switches.yaml

- platform: command_line
  switches:
    energenie_one:
      command_on: curl -s http://[R-Pi's IP Address with :5000 at the end]/api/lamp/1/1
      command_off: curl -s http://[R-Pi's IP Address with :5000 at the end]/api/lamp/1/0
      command_state: curl -s http://[R-Pi's IP Address with :5000 at the end]/api/ener_lamp/1 | grep '1'

- platform: command_line
  switches:
    energenie_two:
      command_on: curl -s http://[R-Pi's IP Address with :5000 at the end]/api/lamp/2/1
      command_off: curl -s http://[R-Pi's IP Address with :5000 at the end]/api/lamp/2/0
      command_state: curl -s http://[R-Pi's IP Address with :5000 at the end]/api/ener_lamp/2 | grep '1'


- platform: command_line
  switches:
    energenie_both:
      command_on: curl -s http://[R-Pi's IP Address with :5000 at the end]/api/lamp/3/1
      command_off: curl -s http://[R-Pi's IP Address with :5000 at the end]/api/lamp/3/0
      command_state: curl -s http://[R-Pi's IP Address with :5000 at the end]/api/ener_lamp/3 | grep '1'

And the snippet for the groups.yaml

  - switch.energenie_one
  - switch.energenie_two
  - switch.energenie_both

will get you this:

A note on the command state, as the Energenies can’t reply with their actual state, this is a once every reboot fudge.

The switches will have to be toggled once before the states match up.

Hope it helps!

edit: And as it’s Beta season, here’s a snippet for the Dashboard:

ener_one:
    widget_type: switch
    title: Ener One
    icon_on: fa-sun-o
    icon_off: fa-sun-o
    icon_style_active: "color: #eae455"
    entity: switch.energenie_one

ener_two:
    widget_type: switch
    title: Ener Two
    icon_on: fa-sun-o
    icon_off: fa-sun-o
    icon_style_active: "color: #eae455"
    entity: switch.energenie_two

ener_both:
    widget_type: switch
    title: Ener Both
    icon_on: fa-sun-o
    icon_off: fa-sun-o
    icon_style_active: "color: #eae455"
    entity: switch.energenie_both

Hi @dave2017,

Have you had any luck getting this to work? I have just bought the same Pi board and 4 Energenie sockets. From the supplied Python file I was hoping to setup 8 python files to control on/off for each of the sockets just like you had suggested.

I wonder how easy it would be to monitor these also?

They are ‘write only’. You have to assume that the command was received and acted upon. There is no indication if someone pushes the button on the sockets to turn them on.

Thanks @gpbenton. I have been reading through the documentation and did come across this. I’d be happy being able to control these through HA.

A suitable approach would be to strip out the individual commands from @dave2017’s post above. This is the Python file that is supplied with the board to control the switches.

I was hoping this may be easy to do with the GPIO component. It seems that the encoder needs several pins set to send the signal to the appropriate switch:

	raw_input('hit return key to send socket 1 ON code')
	# Set K0-K3
	print "sending code 1111 socket 1 on"
	GPIO.output (11, True)
	GPIO.output (15, True)
	GPIO.output (16, True)
	GPIO.output (13, True)
	# let it settle, encoder requires this
	time.sleep(0.1)	
	# Enable the modulator
	GPIO.output (22, True)
	# keep enabled for a period
	time.sleep(0.25)
	# Disable the modulator
	GPIO.output (22, False)

The documentation for this board is here. (Direct link to a PDF)

Cheers for this Bit-River - am I right in assuming you aren’t running this from hass.io?

New to all this, but from what I understand/what I’ve tried, installing pip dependencies from hass.io isn’t possible.

I recently bought myself the Energenie ENER002-2Pi-EU sockets.
Could anyone point me in the right direction to integrate it with hassio?

With thanks

You need something to send them 433MHz signals.

They seem to use a common protocol, as I have some software on a NodeMCU that can decode the remote’s signals, so you can probably use any of the 433MHz projects that are mentioned in the forum (although I haven’t actually done so).

Energenie have a gateway, but this AFAIK has not been integrated with HA.

You could use the Pi-Mote to generate the 433Mhz signals, using some of the software above.

Finally, you could use the two way PiMote with my driver, which uses MQTT messages, but if you are using hassio you will need to convert the driver into an addon.

Ooops, hadn’t checked this thread in a while.

I’m running the above code on a Pi Zero, it will run under Hassbian, and just regular raspbian.

Then I have hassio on an Pi3, calling the switches as above.

Rarely do I ever need to reboot them.

The range can be a little problematic around thick walls / furniture, so I’d always test with them nearby at first.

Hey! Cheers for the reply.

I actually got the range working better on the Pi-mote by putting a cable on the ANT socket.

Also I wrote a switch component to the pimote which works :slight_smile: hoping to get it merged into the main project soon: https://github.com/gwhitelaw/home-assistant/blob/energenie-pimote/homeassistant/components/switch/energenie_pimote.py

1 Like

I control my sockets with rflink. I have a large aerial and the range is great however it does tend to pick up too much data as I can see all my neighbours devices.
I also have the pi-mote board but I couldn’t get the range needed from it.

Ooh, cool! I’ll have to give that a go!

Cheers!

I can highly recommend an RFXCom for many things 433MHz related. It can control Energenie devices from Domoticz, but sadly Home-Assistant doesn’t have the support for Energenie via RFXCom. Maybe one day… :slight_smile: