Home Automation Switch Plate (HASP) - DIY touch controller

I pin pointed the button issue, but unable to resolve it…
It seems Openhab MQTT is not able to read topic with brackets…
Example: “hasp/plate01/state/p[1].b[1]”
Even MQTT.fx fails to receive messages. Both Openhab & MQTT.fx is able to send messages correctly.

Looks like, if this solves, the rest are pretty much ready…

@pkhajanchi - try MQTT-Explorer (I seem to be getting topic updates for buttons through it just fine).

Also, I’m currently working on adding the JSON state topic, if that works well, we won’t need these dedicated button state topics, anyway :slight_smile:

I will wait for you to add JSON state topic. Then will do for 2.4.

It’s very strange, only Openhab and MQTT.fx is not able to read on topics with brackets[]. I tried few other tools and even tried on commandline mqtt-client tool, all are working…

I heard new MQTT2.4 is buggy. But MQTT.fx it’s strange. Same topic, it’s able to send, but nothing on receive…

btw, I tried your code with legacy binding… It’s working perfectly…

1 Like

@pkhajanchi - All set! I’ve added the JSON state topic to my fork of the project:

You can download the .bin file and update your HASP with it to get the additional JSON topic. It will post JSON payloads to the topic when buttons are pressed and dimmers changed.

Topic: hasp/plate01/state/JSON

Payloads:
Button Press:

{"event":"p[2].b[5]", "value":"ON"}

Button Release:

{"event":"p[2].b[5]", "value":"OFF"}

Dimmer Change:

{"event":"p[4].b[7].val", "value":162}

With this, I should be able to replace ALL button/dimmer state items with a single JSON MQTT item, and process the payload in a rule (with a JSONPATH) to figure out what event occurred.

Great! It’s seems to be very easy now… With very few channels and items… Most works required in rules files… I have following suggestion for making this project even better:

  1. Using variables on header for Colors. So that, It can be easily customized.
  2. Rules to change the color or text of the button depending upon its state. Like if Morning Scene is on, then its highlighted, or if an Item is on it’s shown like “Light ON”.

Thing mqtt:topic:plate01 “Plate 01” @ “Living Room”
{
Channels:
Type string : bstate “Plate01 Button State” [ stateTopic=“hasp/plate01/state/JSON” ]
}

ITEM

String plate01_button_press “Plate01 Button State” {channel=“mqtt:topic:plate01:bstate”}

RULE

rule “Button Press”
var event = transform(“JSONPATH”,“$.event”,button_press.state)
var value = transform(“JSONPATH”,“$.value”,button_press.state)

when
item button_press received command
then
if (event==p[2].b[5])
{
// command goes here
}
else if (event==p[2].b[6])
{
//
}

I’ve got the rules set up now - let me clean them up and I’ll post it all to Gothub - the latest firmware is already up, with some minor changes, including the topic name (json vs JSON)…

EDIT: Added .items and .rules files (HASP-Office) for testing the new json state topic - https://github.com/bkpsu/HASwitchPlate/tree/master/contrib/openHAB

Great ideas! I can definitely look into implementing them (#2 would be very simple to add to the event handlers, but only useful for toggle states). I was also thinking of having a method for long-press actions (heating/volume controls for example), but I had to remove the OFF event for now (updates too fast on quick button presses and screws up my rules).

Thanks guys this is awesome work. I got It all working with little trouble. Here are some thing I learnt along the way which may help someone.

Using NODEMCU ESP-12F DEVKIT V3
Mqtt Broker https://mosquitto.org/
Openhabian on PI

Screen not having text after boot

The screen test was not being refreshed straight after boot so in HASP-Master.rules (master stands for the room/screen)

I Changed

/* Restore saved page and rebuild config on reconnect */
rule "HASP Master Restore page on connect"
when
    Item HASP_Plate01_Plate_Sensor_Status changed to "available" or
    Item HASP_Plate01_Plate_Refresh received command ON
then
  
    HASP_Plate01_Page.sendCommand(HASP_Plate01_Page_Current.state as Number) // Send HASP to previous page

To

/* Restore saved page and rebuild config on reconnect */
rule "HASP Master Restore page on connect"
when
    Item HASP_Plate01_Plate_Status changed to "ON" or
    Item HASP_Plate01_Plate_Refresh received command ON
then
  
    HASP_Plate01_Page.sendCommand(HASP_Plate01_Page_Current.state as Number) // Send HASP to previous page

When the 8266 loses power it sends nothing to mqtt but when it is restared it turns the plate_status to OFF then back ON again. It now works instantly.

JSONPath Transformation

If you get the error

[.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH

You need to install JSONPath Transformation to get the data like HASP Plate 01 Sensor - ESP Version. In the PaperUI, choose Configuration -> Extensions -> Transformation (it’s the Headline) LINK

The Nextion editor is what you can use to edit the screen directly it is a very powerful little screen that you can execute code on.

Nextron also have an enhanced version of the screen which has 8 IO on-board. I was thinking of using one of those boards in each room to control some items directly so if openhab stops working or the pi dies it won’t effect the ability to be able to turn the lights off. I think I will need this to get WIFE approval.

Things I am Currently working on

  • Backlight rules to dim backlight when lights are off
  • Turn screen backlight off after time and back on when press detected
  • Change background colour of buttons to show state
1 Like
  • Backlight rules to dim backlight when lights are off

Missed it until now but they use the expire binding to turn off back light.

If you install the expire1 the backlight turns of and when you press the screen it turns on and also unfortunately you also trigger the button.

Good change! I didn’t think of using the Plate_Status, and had a hard time with the rule sending that entire batch of init data to the plate constantly, so I went with something more manual (i.e. the “Refresh” switch). I’ll try your way to see if that works without the constant resends.

Yes - sorry for not making that obvious in the first post - I’ll update it so others don’t come across the same issue.

luma has done a lot of work to make that HMI flexible and useful for many different applications. I haven’t seen the need to make any updates to the HMI layout, but you’re right, it’s very powerful. Just be aware that Nextion is basically re-branding TJC display hardware and software (half the price, more functionality on the TJC side). You can get the TJC displays cheaper on eBay, and use the firmware/HMI firmware luma made available on his GitHub, to save on the cost.

I already do this in my rules, using the expire binding. Just set the value in the expire=“30s,command=OFF” clause in the HASP_Plate02_Light_Power item definition to what you want.

The other two things you’re working on are specific to personal setups, but very cool, too! The button background color change is something @pkhajanchi also suggested, and I’ve been thinking about how to do that. The colors are currently hardcoded into rules, and Pankaj suggested I use variables at the top of the rule. But, I’d like to take that a step further, and have Color items in the main configuration, which would be used to send the background/foreground color to the HASP. The biggest issue is the HMI uses a non-standard color code (integer value between 0 and 65536), so there has to be a translation rule that will take the HSB type from the Color item, and translate it to the Nextion value).

Fortunately, the conversion has already been figured out, and there’s even a converter site on Github (Online Nextion HMI Color Converter) so we can use the formula in our transcoding rule.

Are you sure you’re running the latest firmware bin (version 0.37) I uploaded to my Github? I removed the “OFF” event from the JSON state topic, because the events were coming in too fast (and doubling up the button press rule). With the latest code, only the “ON” event is passed, so pressing the plate when turned off will bring it back up to full brightness, but won’t register as a command button press.

Yes I using latest firmware bin found bkpsu/HASwitchPlate/tree/master/Arduino_Sketch

I downloaded and updated it again to be sure. After waiting for the time out I gave it a quick touch to wake it up and still received a touch event in the log.

HASP_Plate01_Button_P2B7 changed from OFF to ON
Just touch the bottom of the screen for now

2019-02-16 23:40:58.651 [ome.event.ItemCommandEvent] - Item ‘HASP_Plate01_Light_Power’ received command OFF
2019-02-16 23:40:58.672 [vent.ItemStateChangedEvent] - HASP_Plate01_Light_Power changed from ON to OFF
2019-02-16 23:40:58.766 [vent.ItemStateChangedEvent] - HASP_Plate01_Light_Status changed from ON to OFF
2019-02-16 23:41:09.747 [vent.ItemStateChangedEvent] - HASP_Plate01_Button_P2B7 changed from OFF to ON
2019-02-16 23:41:09.784 [ome.event.ItemCommandEvent] - Item ‘HASP_Plate01_Light_Power’ received command ON
2019-02-16 23:41:09.802 [vent.ItemStateChangedEvent] - HASP_Plate01_Button_P2B7 changed from ON to OFF
2019-02-16 23:41:09.806 [vent.ItemStateChangedEvent] - HASP_Plate01_Light_Power changed from OFF to ON
2019-02-16 23:41:09.829 [vent.ItemStateChangedEvent] - HASP_Plate01_Light_Status changed from OFF to ON

I got an easy way to fix it just need to be tested.

Ah, I see what the issue is - you’re still using the original Items/Rules I posted. Last weekend, I updated the files to use the latest JSON state format, deleting all of those unnecessary “discrete” items for each button, dimmer, background color, etc…

Check out the Github contrib/openHAB folder, and download the items/rules files from there. They’ll make your configuration much simpler (and get rid of the issue you’re seeing with the backlight).

Ahh yes that’s got It thanks.

It also works good with the change

rule "HASP Master Restore page on connect"
when
    Item HASP_Plate01_Plate_Status changed to "ON" or
    Item HASP_Plate01_Plate_Refresh received command ON
then
1 Like

Yup - just tested it on mine and it works perfectly! Refreshes on connection and no extra refreshes after that - thanks! :slight_smile: I’ll update my Github repo to incorporate this improvement.

Hi. Just been playing with HASP and the latest version of the rules and firmware from this thread. Very happy so far.

Can I ask for a point in the right direction on how to process some of the incoming dimmer items?

I had a look at the example for the backlight dimmer in the rules, but need to scale the 0-254 from the slider to 0-100% before sending to a Tasmota based dimmer item.
I dont have a great deal of rules experience, so there may be much more straightforward way to approach this. See code below that seems to extract the dimmer value okay, but fails at the scaling (openhabian 2.3).

 //Insert action to perform if dimmer 2 was moved
                                logInfo("HASP-rule","dimmer rule command ")    
                                logInfo("HASP-rule","dimmer state in = "+ HASP_Plate01_Plate_State_JSON_Value.state.toString
                                var Number incoming_dimmer_number = HASP_Plate01_Plate_State_JSON_Value.state
                                logInfo("HASP-rule","incoming number as a number= "+incoming_dimmer_number)  
                                var Number adjust_incoming_dimmer_number = incoming_dimmer_number*100/255     
                                logInfo("HASP-rule","outgoing= "+adjust_incoming_dimmer_number)
                                Lounge_SideDimmerTest_Level.sendCommand(adjust_incoming_dimmer_number)

Log shows the original number being extracted okay, but then failing at the scaling line;

2019-02-23 15:26:26.055 [INFO ] [pse.smarthome.model.script.HASP-rule] - dimmer rule command 
2019-02-23 15:26:26.061 [INFO ] [pse.smarthome.model.script.HASP-rule] - dimmer state in = 109
2019-02-23 15:26:26.067 [INFO ] [pse.smarthome.model.script.HASP-rule] - incoming number as a number= 109
2019-02-23 15:26:26.071 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Handle HASP Master': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.lib.NumberExtensions.operator_multiply(java.lang.Number,java.lang.Number) on instance: null

Can anyone give me a hint, or point in the right direction?

Thanks.

I think the incoming_dimmer_number value is being treated as a string in your conversion formula…try changing the rule to the following:

 //Insert action to perform if dimmer 2 was moved
                                logInfo("HASP-rule","dimmer rule command ")    
                                logInfo("HASP-rule","dimmer state in = "+ HASP_Plate01_Plate_State_JSON_Value.state.toString
                                var Number incoming_dimmer_number = HASP_Plate01_Plate_State_JSON_Value.state
                                logInfo("HASP-rule","incoming number as a number= "+incoming_dimmer_number)  
                                var Number adjust_incoming_dimmer_number = (incoming_dimmer_number*100/255).intValue     
                                logInfo("HASP-rule","outgoing= "+adjust_incoming_dimmer_number)
                                Lounge_SideDimmerTest_Level.sendCommand(adjust_incoming_dimmer_number as Number)

(I also added the “as Number” in your sendCommand routine, to ensure we send a number value to the Tasmota dimmer.

1 Like

Ok so I have had some time and I have put a weather Icon on my 2nd page.

weather_screen

ITEMS
I added this item

String HASP_Plate01_weather_tranformed "Picture Number to Display on Plate 01" { channel="openweathermap:weather-and-forecast:api:local:current#condition-id"[profile="transform:MAP", function="nextionIcon.map"]}

RULES

Modify rules file to handle requesting icon being shown on screen

rule "Handle HASP Master Page 2 Status"
when
     Item HASP_Plate01_weather_tranformed received update or
     Item localCurrentTemperature received update or

//  Other Code here

then

    if (HASP_Plate01_Page_Current.state == 2)   //Only update page if you're on page 2 (avoid sending too many MQTT messages)
    {
        var jsonString ='["weather.pic=' + HASP_Plate01_weather_tranformed.state + '", ' +

//                                other parts of your string here 
- bartus B K and the HASP team have done awesome job I just adding to it

Nextion Screen
you need to update the screen in the Nextion Editor or just download this one HASwichplate_weather.tf
I just updated it through the 8266 and it worked fine for me. Their is a HMI file in my github here

You can upload your own Icons but you can’t name the picture resource onto the screen. So you must map it to do this I used Map.

Transformation

I used Map transformation to map the data

Install here - Paper UI >Add-ons >Transformations tab >Map Transformation

You need to crate a map file in your transform directory called nextionIcon.map
Contence of my map file.

200=1
201=1
202=1
210=1
211=1
212=1
221=1
230=1
231=1
232=1
300=2
301=2
302=2
310=2
311=2
312=2
313=2
314=2
321=2
500=3
501=3
502=3
503=3
504=3
511=3
520=2
521=2
522=2
531=2
600=4
601=4
602=4
611=4
612=4
615=4
616=4
620=4
621=4
622=4
701=5
711=5
721=5
731=5
741=5
751=5
761=5
762=5
771=5
781=5
800=6
801=7
802=8 
803=9
804=9

The items on the left are the weather conditions and on the right is the picture to display on Nextion. If you change Icons let me know these are 50x50 but 64*64 would be better.

Next I will be putting all my aircon controls on the screen.

2 Likes