Saturday 26 March 2022

Setup OpenHasp on lanbon L8 with HomeAssistant


 So my Lanbon L8 light switches were seriously buggy. Problems included;

  1. Mesh WiFi network was flawed and consistently losing connectivity
  2. Artifacts on the screen and buttons in a stuck mode
  3. Random rebooting of the switches
  4. Sluggish response from the touch screens
  5. Firmware doesn't automatically update, requires contact with supplier to do anything.
  6. Doesn't easily working with Home assistant

So, I had a look at what custom firmwares were available and found this;

Custom Firmware on Lanbon L8 LCD Touch Switch | Blakadder's Smarthome Shenanigans

Which was pretty good, but still lacked the detail of how this things works, just sort of showed how to get started. Thought it would be a good idea to go into some detail for new comers.

This article will walk through the firmware to configuration on home assistant including a few extra learnings...

Prerequisites;

  1. USB to serial (ardiuno writer) (like this CP2102 module USB to TTL serial UART STC download cable PL2303 Super Brush line upgrade for arduino|Integrated Circuits| - AliExpress)
  2. A LanBon L8 light switch
  3. Recommended - Ethernet cable, dupont connectors and dupont crimper
  4. Home Assistant (Supervised) 
  5. Home Assistant Add-on  "Mosquitto Broker" (MQTT broker addon)
  6. Home Assistant Add-on "Terminal & SSH"
  7. Home Assistant Add-on "HACS repository" (GitHub - hacs/integration: HACS gives you a powerful UI to handle downloads of all your custom needs.)
  8. From the HACS repository install the "openHASP integration"
  9. On your PC you will need;
    1. Install Arduino IDE
    2. Install ESP driver support (Installing — Arduino-ESP32 2.0.2 documentation (espressif.com))
    3. Install pyserial
    • Command is "pip install pyserial"
      • I don't remember if python came with the IDE, but you may need python for this as well if it didn't

Do a search after this, you should find the file "esptool.py" in one of you directories under "arduinodata"

I am going to assume you have installed all the above and you have some experience with the above...

Connecting the Lanbon L8

Not going to reinvent the wheel... BlakAdder explains it well see pictures, i used the same method, old ethernet cable with dupont attachments + I also used a small crocodile clamp to short IO1 and GND

Connection\Mapping between the USB to serial converter and the L8 is;

USB   | L8
RX     | TX
TX     | RX
IO1    | GND  (this is what tells the device you are writing the ESP chip inside it)
GND | GND
+5v    | +5v

Any work you do with the ESP memory IO0 must be in GND
If you hooked in correctly (with IO0) you should get a white screen (NOT the lanbon OS booting up)



Backup;

You can skip this step, but i like to have a backup of the working image in case this doesn't work and need to flash it back.

*****IMPORTANT ***** Everytime you do an action with the L8 and ESP memory you will need to reboot it.

* Run in administrative command prompt from the esptool.py directory

Please note my COM port was COM3, you will need to find yours (best is to load the Arduino IDE and take a look at "Tools->Port")

esptool.py --port COM3 --baud 921600 flash_id

Read the memory size (mine was 8MB)


Reset the device (this means disconnect +5V and reconnecting it), then;

esptool.py --port COM3 --baud 921600 read_flash 0 0x800000 c:\temp\lanbonL8OriginalFlash.bin

--The 0x800000 will equate to 8MB of memory

Writing OpenHASP to the device

Download openHASP image from here; Releases · HASwitchPlate/openHASP · GitHub

I did this with version 0.6.2 -https://github.com/HASwitchPlate/openHASP/releases/download/v0.6.2/lanbon_l8_full_8MB_v0.6.2.bin

  1. Reset the device (this means disconnect +5V and reconnecting it)
  2. Erase the current OS
    • esptool.py --port COM3 erase_flash
  3. Reset the device
  4. Write the openHASP image to the device
    • esptool.py --port COM3 --baud 921600 write_flash 0x0 lanbon_l8_full_8MB_v0.6.2.bin


Configure the "Plate"

Thats it, you have now installed openHASP on the Plate, next step configuring it;

For reference here is how it fits together;


Once write confirmed remove IO0 from Ground and reboot.Should show this 


Add to wifi manually (should get an IP pop up)

Then you should see this;



In a web browser put the IP that it got from DHCP.

Now I had an issue that after a few minutes the web console stopped responding, this is a known issue with the serial console. Too stop this happening we have to shutdown the console once the Network switches on.


In the "file editor" on the web page, add this line;
service stop console

Should look like this;


I uploaded mine (couldn't figure out how to edit files in the editor)

Next enter the MQTT broker details;


Note the HASP node name is the device name going forward

Save settings then reboot the device (can do from the web interface now)


If you have done everything as expected you should be able to see it on the MQTT broker using MQTT explorer.

Next is configuring the GPIOs for the relays and mood lights. You can do this manually but its far easier using MQTT explorer;

Send the following json to hasp/[mqttnodename]/config/gpio

{"config":[197658,263456,329249,655628,655886,656155,0,0]}


See example:


At this point I highly recommend you check the web page of the Plate to make sure the PINs are now configured.


Setting the display up

So all the base setting up is done, now we need to draw up the GUI. I am not going to go into something complex, rather I will give you my first "pages.jsonl" to work with;

{

"page": 0, 

"id": 1, 

"x":0, "y":0, "w":80, "h":20, 

"comment": "Time in the top left", 

"obj": "label", 

"text_color": "#FFFFFF", 

"text": "00:00", 

"align": "left", 

"bg_color": "#2C3E50"

}

{

"page": 0, 

"id": 2, 

"x":160, "y":0, "w":60, "h":20, 

"comment": "Temp", 

"obj": "label", 

"text_color": "#FFFFFF", 

"text": "00.0", 

"align": "right", 

"bg_color": "#2C3E50"

}

{

"page": 0, 

"id": 3, 

"x":220, "y":0, "w":20, "h":20, 

"comment": "Temp sign", 

"obj": "label", 

"text_color": "#FFFFFF", 

"text": "°C", 

"align": "right", 

"bg_color": "#2C3E50"

}

{

"page": 0, 

"id": 6, 

"x":0, "y":300, "w":80, "h":20, 

"comment": "tab nav on the bottom, prev", 

"obj": "btn", 

"action": "prev", 

"bg_color": "#2C3E50", 

"text": "\uE141", 

"text_color": "#FFFFFF", 

"radius": 0, 

"border_side": 0, 

"text_font": 28

}

{

"page": 0, 

"id": 7, 

"x":80, "y":300, "w":80, "h":20, 

"obj": "btn", 

"action": "back", 

"bg_color": "#2C3E50", 

"text": "\uE2DC", 

"text_color": "#FFFFFF", 

"radius": 0, 

"border_side": 0, 

"text_font": 22

}

{

"page": 0, 

"id": 8, 

"x":160, "y":300, "w":80, "h":20, 

"obj": "btn", 

"action": "next", 

"bg_color": "#2C3E50", 

"text": "\uE142", 

"text_color": "#FFFFFF", 

"radius": 0, 

"border_side": 0, 

"text_font": 28

}

{

"page": 1,

"id": 101, 

"x":0, "y":30, "w":240, "h":80, 

"comment": "relay1", 

"obj": "btn", 

"toggle": true, 

"text": "\uEA70 Dining Room", 

"mode": "break", 

"align": "center", 

"groupid": 1

}

{

"page": 1, 

"id": 102, 

"x":0, "y":120, "w":240, "h":80, 

"comment": "relay2", 

"obj": "btn", 

"toggle": true, 

"text": "\uF1E1 Kitchen Bench", 

"mode": "break", 

"align": "center", 

"groupid": 2

}

{

"page": 1, 

"id": 103, 

"x":0, "y":210, "w":240, "h":80, 

"comment": "relay3", 

"obj": "btn", 

"toggle": true, 

"text": "\uF054 Outdoor Trampoline Area", 

"mode": "break", 

"align": "center", 

"groupid": 3

}


Here are a couple of key details;

  • Page 0 is common for all pages (header and footer page) 
    • The time and temperature will be fed back (to the placeholder) from the HA server they do not live on the plate at all.
  • The id will be referenced later in Home Assistant
  • Special images are in the font and can be used using \uABCD
  • Groupid relates to the GPIO port it will use

Okay, now upload it via the web page via the HASP Designer, save and REBOOT.

Should look something like this... But without the time and temperature (as HA isn't configured)


The switch should now work with the relays even with out home assistant, so you can detach the cables and stick it back on the wall...

Configuring Home Assistant

Open up the terminal on the home assistant web page.

Goto the config directory

cd config

I am going to assume you know how to use the vi editor or something similar, not going to go into it here, google vi editor if you dont know how to use it...

vi configuration.yaml



Insert the line "openhasp: !include openhasp.yaml"

Write and quit the file.

You could insert the code into this file but it would be long and painful, not recommended

vi openhasp.yaml


DO NOT USE TABS in the file, it will not parse correctly if you do.

  • Sensor.time I added and entity to Home assistant to show time on unit
  • Sensor.hue is a philips motion sensor that I am pulling the temperature from.
Check the configuration on Home assistant (Under Configuration->Settings)
Hit "check configuration"

So long as it parses hit the "RESTART" under Home Assistant


Summary


Hope you enjoyed this tutorial, i put it together so i remember what i did next time i have to change something.
All the issues I raised at the start are resolved with this firmware, so highly recommended, but not for those with no will to tinker....

  1. Mesh WiFi network was flawed and consistently losing connectivity - Resolved
  2. Artifacts on the screen and buttons in a stuck mode - Resolved
  3. Random rebooting of the switches - Resolved
  4. Sluggish response from the touch screens - Resolved
  5. Firmware doesn't automatically update, requires contact with supplier to do anything. - Resolved
  6. Doesn't easily working with Home assistant - Resolved

No comments:

Post a Comment