I’ve recently hooked up a few Lanbon LS-HS’s to some lighting circuits in my flat and i was determined to get them working with Home assistant using Openhasp. I started out with the stable v0.5.1 firmware for the L8 and wasn’t getting anywhere as it didn’t seem like any of the output commands would actually toggle the gpio outputs, but thanks to some help from fvanroie i ended up using the v0.6.0 dev build which apparently has improved gpio support.
After a bit of experimenting it turns out that in order to get the GPIO’s to change you can’t currently use the GPIO groups and have to use the GPIO pin numbers themselves. As an example, for the Lanbon L8-HS Relay 1 is connected to GPIO pin 12. What you have to do is send the payload to hasp/<mqtt_topic>/command/output12 in order to get Relay 1 to switch. In addition, the payload can’t be 1, on or true. The way i could get it to switch was to set the payload to {“state”:1} or {“state”:0}, then the relay switches. The other outputs on the Lanbon L8-HS are connected to GPIO’s 14 and 27 and i’ve confirmed those work in the same way.
At the moment with the current dev build i’ve potentially found another quirk which caused me a bit of confusion til i figured out what was going on. In order for these MQTT commands to work i needed to include an object on a page that was linked to the GPIO group and that object had to be manually activated on the plate at least once before the MQTT commands would work. That means after every reboot of the plate you needed to manually press each object once to allow it to be operated using MQTT. I confirmed this behaviour on four of the Lanbon’s, but if anyone else fancies trying this then could you let fvanroie know if you had the same issue or if it was something i was doing?
In order to get this working in Home assistant i’ve created a lighting template that sends the appropriate MQTT command when it’s turned on and off. In addition, i’ve linked that value and state of the light template to the object on the plate, so that way it doesn’t matter if the light is switched by the plate or by Home assistant, they both show the correct state and stay in sync.
As an example you could send the following jsonl to the plate:
{"page":1,"id":1,"obj":"btn","x":3,"y":40,"w":234,"h":130,"toggle":true,"groupid":"1","text":"Hall Lights \uE335","text_font":32,"mode":"break","align":1}
With that programmed you could add the following to the your home assistant configuration.yaml file:
light:
- platform: template
lights:
hall_light1:
friendly_name: "Hall light entrance"
turn_on:
service: mqtt.publish
data:
topic: hasp/mainlight_hall/command/output12
payload: '{"state":1}'
turn_off:
service: mqtt.publish
data:
topic: hasp/mainlight_hall/command/output12
payload: '{"state":0}'
openhasp:
mainlight_hall:
topic: "hasp/mainlight_hall"
idle_brightness: 35
objects:
- obj: "p1b1" # light-switch toggle button
properties:
"val": '{{ 1 if states("light.hall_light1") == "on" else 0 }}'
"text": '{{ "Hall Lights \uE6E8" if is_state("light.hall_light1", "on") else "Hall Lights \uE335" | e }}'
event:
"up":
- service: homeassistant.toggle
entity_id: "light.hall_light1"
This will create a light entity that will send the MQTT command to switch the lights on and off when it’s switched in home assistant, but the openhasp instance keeps everything in sync so even if you switch the lights on the plate the light entity in home assistant will update. This also means that if you want to switch the light on or off from another plate you just link it to the template. The only restriction at the moment is that if you have to reboot the Lanbon for whatever reason you need to manually switch the object linked to the gpio group before it can be controlled by home assistant.
I should also mention that i have the HACS openhasp repo installed and it’ll give a warning that the plates are running a different version of the firmware than it’s expecting.