@bartus (B K) posted a new topic, subject "Home Automation Switch Plate (HASP) - DIY touch controller". It read: As mentioned in my What did you build/automated today (with pictures)? post recently, I've been able to adapt the Home Automation Switch Plate (HASP) project to work with openHAB. I'm posting a write-up here, in case anyone else is interested in using it. * * * ## What is it? The HASP is a touch screen controller designed by aderusha (project page on Github), which fits into a spare “gang” in US-style electrical outlets (no design for the rest of the world yet, sorry). It uses a Nextion HMI (2.4") touchscreen, with a user interface designed by aderusha (9 total screens of different layouts with pushbuttons, sliders and a chart), and a Wemos D1 to drive the screen and interface with the control system (via MQTT). The finished product looks like this: image.png1707×551 125 KB * * * ## How does it work? The Wemos D1 Arduino code and the Nextion HMI code are very nicely designed, made to be modular and generic, exposing all configuration to the home automation system incorporating the HASP. Every button text, background/foreground color, and font size are configurable via MQTT topics. Every button press is captured and sent to the home automation system via MQTT, as well. Once flashed with code, the HASP allows easy configuration via Wifi (it creates an access point for connection and initial configuration). The initial load of the HMI code is via an SD card with the Github .tft file provided. After that, the HASP can be accessed via a webpage, to change its MQTT settings, Wifi settings, or even update the Wemos (ESP) and LCD (TFT) firmware via HTTP! This is a very cool feature to keep the display up to date! image.png811×773 25.7 KB * * * ## How to build one? The GitHub repo has excellent build documentation available, but I also created a short series of build and setup videos. Part 1 (Hardware build and software configuration): Part 2 (Install and openHAB configuration): * * * ## How to use it with openHAB? The initial project was designed specifically for Home Assistant, with the yaml configuration files included in the GitHub. But after looking at it for a while, I was able to mimic the automation rules for openHAB and I created a set of configuration files for OH. I've submitted a PR to aderusha and it's been approved/merged to the HASP repository, under the /contrib/openHAB folder. I won't post the .items or .rules files here due to their length, but the files are available at the Github repo, and I've included a sample .sitemap file stub to be able to control/monitor status of the HASP via the Basic UI. I've included a lot of comments in the items and rules files, a readme file on the GitHub repo, and sectioned off the rules file to make it clearer where the end user is able to modify their HASP, but the gist of configuration is as follows: 0. Before you start, make sure you have the JSONPath transformation installed, the Rules & Items make use of it to decode the data received from the HASP. 1. Decide which screens of the HMI you want to use. For example, my initial configuration will use screens 1, 2 and 4: a. Screen 1 has 4 buttons, which I'll use to fire off a specific Scene in my openHAB setup b. Screen 2 also has 4 buttons, which I'll use to show a clock, date, indoor and outdoor temperatures c. Screen 4 has 3 buttons and 3 sliders, which I'll use to control my HVAC system and possibly another light depending on which room the HASP is installed. 2. Depending on the configuration selected above, adjust the variables in the rules file to match the configuration: a. In the first part of the .rules file, make the bottom buttons point to the correct screen # and label them. b. Adjust the variables corresponding to the button text and font size on the screens with buttons and sliders. 3. Fill in the HASP -> openHAB and openHAB -> HASP rule sections with the appropriate handler rules for your configuration. a. The HASP -> openHAB rules section has stub rules written for every button/slider on every screen. You'll only need to fill in your code into the appropriate if statement to handle the button press/slider move (I've put in commented out example code for some of the cases). b. The openHAB -> HASP rules section has some sample rules I've written to move the sliders to an appropriate position based on openHAB item state (e.g. to match the brightness slider of a light if it's changed from some other interface than the HASP) and to put values on the chart of page 9 (e.g. to monitor the signal strength of the HASP Wifi signal, or to show a chart of the room temperature over time). 4. Enjoy using the HASP! * * * ## Conclusion / Notes image.jpg1292×969 203 KB My rules and items files should make it easier to incorporate the HASP into our openHAB setups, but there's still work to be done by the end user to make the buttons and sliders actually “do things”. I've also not included some of the finer configuration items (background colors), since I was mostly concerned with getting the main functionality to work. I may add those items/rules in the future, if needed. Let me know if you have any questions or issues with using this After which, @pkhajanchi (Pankaj) added Great Work! But unfortunately this is not working on my setup… I am using Openhab 2.4 MQTT bindings and I guess your codes are for legacy MQTT… Can anyone help in converting it to 2.4 MQTT Binding? To which @bartus (B K) replied You can still run the MQTTv1 binding alongside MQTTv2.4 to make this work as-is (just enable “Use Legacy Bindings” option in your Paper UI System Configuration page and install/configure the MQTTv1 binding). I haven't taken on the task of converting this to MQTTv.2 because of the sheer amount of MQTT topics/channels required per unit. Ideally, the HASP Arduino code should be updated to support the Homie 3.0 protocol, so that all the MQTT topics/channels are automatically discovered/configured by the binding. I may take on that task, when I'm done with some of my other concurrent projects @pkhajanchi (Pankaj) replied Really appreciate your fast reply… I am thinking of converting your code for proper latest MQTT2.4. I will be able to convert most of it, just not completely sure about rules… currently cooking Things files and Items files… To which @bartus (B K) replied @pkhajanchi \- That'd be awesome and I'd appreciate the help! Let's coordinate the changes a bit, though, so you don't end up doing unnecessary work. Basically, here's my thoughts: 1. (DONE) ~~The latest HASP firmware from luma (aderusha) allows the use of JSON arrays to string multiple commands together (up to 4Kb strings, if I remember correctly). I'm already using that in the page command button and page button color rules, and it means I can eliminate all the “formatting” (font, background color, etc…) items with dedicated MQTT topics related to those buttons (can still access those settings via JSON commands). As an added bonus, the JSON command strings are parsed by the HASP a lot faster than individual MQTT messages, making for a smoother/more responsive HASP. So, I'd like to convert all the openHAB- >HASP rules to use JSON commands, and eliminate all of the formatting items (keeping only the Page/Button items for the HASP -> openHAB callback rules). I can (hopefully) take care of this tomorrow.~~ 2. With this limited set of Items, it should be much simpler to convert them to MQTTv2, just adding channels for each specific button on every page. I also reached out to luma about supporting the Homie (v4!) protocol. That way, we wouldn't have to manually create MQTTv2 channels at all, they would be automatically created by the binding, with auto discovery…Whether this happens or not, step 1 above should still be the first thing we do to reduce the overall item/topic count! To which @bartus (B K) replied @pkhajanchi \- I just uploaded my changes to the .items/.rules files to convert to using the JSON command topic for all formatting (text, font, background color) items. With this, I was able to delete all of those individual dedicated items, leaving only the button/dimmer value and general HASP status items (cut the .items files down by half!). Updated files are in my Github repo (https://github.com/bkpsu/HASwitchPlate/tree/master/contrib/openHAB) If you're still willing to work on converting the items to MQTTv2 channels, you should have a (slightly) easier task at this point, though I would still recommend waiting to see if luma will support the Homie convention! Then @pkhajanchi (Pankaj) said I saw your message late, already did get 3 pages and others things working. I am attaching the working Things files and Items file. Rules files, was same as all the items name I kept the same… HASP-Master.items.txt (24.0 KB) plate01.things.txt (20.3 KB) Only one small issue was left, Buttons was having problem. But, now mostly I will discard it, and start as per your suggestions… After which, @bartus (B K) added Excellent work @pkhajanchi! Sorry you had to do the extra items, I was hoping to complete my task so you'd have less work to go through. I'm going to send luma a PR for the changes I've made today - when you finish your changes, you can either send the files to me (upload them here), or create a new PR to aderusha's repostiory (https://github.com/aderusha/HASwitchPlate/) yourself. BTW, I've also created a new Issue on aderusha's repo (https://github.com/aderusha/HASwitchPlate/issues/52), for him to add a single JSON “status” topic with events for every button press/dimmer value change. I think that would streamline the interface even more, and allow us to really reduce the number of items/MQTT channels. Then, adding Homie support would be trivial… Thanks again! So @pkhajanchi (Pankaj) replied 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… After which, @bartus (B K) added @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 Then @pkhajanchi (Pankaj) said 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… Then @pkhajanchi (Pankaj) said btw, I tried your code with legacy binding… It's working perfectly… So @bartus (B K) replied @pkhajanchi \- All set! I've added the JSON state topic to my fork of the project: GitHub ### bkpsu/HASwitchPlate LCD touchscreen for Home Automation. Contribute to bkpsu/HASwitchPlate development by creating an account on GitHub. 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: [code] {"event":"p[2].b[5]", "value":"ON"} [/code] Button Release: [code] {"event":"p[2].b[5]", "value":"OFF"} [/code] Dimmer Change: [code] {"event":"p[4].b[7].val", "value":162} [/code] 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. So @pkhajanchi (Pankaj) replied 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”. @pkhajanchi (Pankaj) replied bartus: > hasp/plate01/state/JSON 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]) { // } Then @bartus (B K) said 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 @bartus (B K) replied pkhajanchi: > * Using variables on header for Colors. So that, It can be easily customized. > * 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”. > 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). @denominator (James Bowler) replied 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 [code] /* 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 [/code] To [code] /* 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 [/code] 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 After which, @denominator (James Bowler) added * 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. After which, @bartus (B K) added denominator: > 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. 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. denominator: > You need to install JSONPath Transformation to get the data Yes - sorry for not making that obvious in the first post - I'll update it so others don't come across the same issue. denominator: > 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. 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. denominator: > Turn screen backlight off after time and back on when press detected 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 (https://nodtem66.github.io/nextion-hmi-color-convert/index.html) so we can use the formula in our transcoding rule. @bartus (B K) replied denominator: > 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. 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. So @denominator (James Bowler) replied 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. So @bartus (B K) replied 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). To which @denominator (James Bowler) replied Ahh yes that's got It thanks. It also works good with the change [code] 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 [/code] @bartus (B K) replied Yup - just tested it on mine and it works perfectly! Refreshes on connection and no extra refreshes after that - thanks! I'll update my Github repo to incorporate this improvement. So @LukeCorkill (Luke Corkill) replied 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). [code] //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) [/code] Log shows the original number being extracted okay, but then failing at the scaling line; [code] 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 [/code] Can anyone give me a hint, or point in the right direction? Thanks. After which, @bartus (B K) added I think the incoming_dimmer_number value is being treated as a string in your conversion formula…try changing the rule to the following: [code] //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) [/code] (I also added the “as Number” in your sendCommand routine, to ensure we send a number value to the Tasmota dimmer. So @denominator (James Bowler) replied Ok so I have had some time and I have put a weather Icon on my 2nd page. **ITEMS** I added this item [code] 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"]} [/code] **RULES** Modify rules file to handle requesting icon being shown on screen [code] 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 [/code] **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. [code] 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 [/code] 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. After which, @bartus (B K) added @denominator \- this is awesome!! Definitely a useful/pretty addition. You should create a PR on aderusha's GitHub so it can be brought into the master branch (aderusha (luma) updates the firmware on both the ESP & HMI constantly, so you wouldn't have to add your icons every time he releases a new HMI version it they're in the master). He's also working on an HVAC control screen (different button/dimmer layout), so you _can_ wait for that if you don't want to duplicate efforts. Then @Stewart-MyNerdLab (Stewart ) said I have just the Demo of you HASP install, how do I add the state of a MQTT temp sensor to the HASP? Do I add the item in the rules file, I have no Idea where to start with his one @bartus (B K) replied Stewart - you'd want to send the state of the item state when the MQTT temp sensor state changes. Take a look at the page 2 rule and use it to adapt it to your case: [code] rule "Handle HASP Foyer Page 2 Status" when Item <<YOURSENSORITEM>> received update or Item HASP_Plate02_Page_Current received update 2 then if (HASP_Plate02_Page_Current.state == 2) //Only update page if you're on page 2 (avoid sending too many MQTT messages) { var jsonString = '["p[2].b[4].txt=\\"' + <<YOURSENSORITEM>>.state.format("%.1f °F") + '\\""] ' HASP_Plate02_Plate_Command_JSON.sendCommand(jsonString) } end [/code] You should be able to replace <> with your device item and make it work that way. So @SHP-Stewart (Stewart ) replied Thank BK it works but I am not sure how, I created a new rule file and just pasted the sample you gave and changed the item, reloaded the HASP and it works. The way It look to me but correct me if i am wrong, is that “when” Item get and update, “then” it passes the sensor state to p2 b4 (page2 button 4) and then send the command to the HASP After which, @bartus (B K) added That's exactly what it's doing Whenever you temperature item is updated, you're using that rule to update the “txt” component on the button (basically, the button text). The way HASP works is it simply provides the buttons/dimmers in a blank configuration, you have to set the actual “state” (value for dimmer, text for button). After which, @ruangreeff (Ruan) added Managed to build my HASP and it is connected to Openhab. I was able to configure a couple of buttons to control devices but am unable to get the status page to display anything other than the “Line 1 - 4”. Installed openweathermap and the Sitemap displays all data although the HASP does not want to display the current Temperature. Would appreciate some help. The Date and Time does not even show up Then @SHP-Stewart (Stewart ) said Have to tried to reset the device from the web UI as this worked for me. But failing that BK hobby said that you need to create additional sets of rules so that when an Item or thing get and update it updates the button on the screen. To which @bartus (B K) replied @ruangreeff \- check out my rules for the HASP (https://github.com/bkpsu/openhab2-conf-bartus/blob/master/rules/HASP-Foyer.rules) - line 499 is where the rule to update page 2 starts. Since there have been a few changes since the original post, make sure you: 1. Download the latest (0.37) firmware for your plate (you can do the firmware upgrade from the plate webpage, since aderusha already approved my pull request for JSON status. 2. Use the latest .items & .rules file from my repo, since I converted to using all JSON for commands & status. If you're already using the latest firmware/rules, I'd check to make sure you have the JSON string being built correctly. It's very easy to screw that up, with all the opening/closing quotes in the string. The HASP won't freeze or anything if you send it a bad command string, but it will just ignore it without saying anything. So @denominator (James Bowler) replied I made some more changes here is what I have for the Scenes page 1. In the HASP-master.rules file I changed case 1 to look like [code] case '1': { /* Act on buttons from Page 1 here */ if (eventbutton == '4') { //Insert action to perform if button 4 was pressed Scene_Master.sendCommand("Morning") } else if (eventbutton == '5') { //Insert action to perform if button 5 was pressed Scene_Master.sendCommand("Evening") } else if (eventbutton == '6') { //Insert action to perform if button 6 was pressed Scene_Master.sendCommand("Night") } else if (eventbutton == '7') { //Insert action to perform if button 7 was pressed Scene_Master.sendCommand("Bedtime") } HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press } [/code] Of course I needed to add Scene_Master to items [code] String Scene_Master "Bedroom Scene" [/code] Now to add a rule to change the colour [code] val scn_en = '28388' //25388 is default grey val scn_dis = '65535' // white rule "Show Scene on Nextion" when Item HASP_Plate01_Plate_Status changed to "ON" or Item Scene_Master changed then if (Scene_Master.state == "Morning") { HASP_Plate01_Plate_Command_JSON.sendCommand('["p[1].b[4].bco=' + scn_en + '", "p[1].b[5].bco=' + scn_dis + '", "p[1].b[6].bco=' + scn_dis + '", "p[1].b[7].bco=' + scn_dis + '"]') } else if (Scene_Master.state == "Evening") { HASP_Plate01_Plate_Command_JSON.sendCommand('["p[1].b[4].bco=' + scn_dis + '", "p[1].b[5].bco=' + scn_en + '", "p[1].b[6].bco=' + scn_dis + '", "p[1].b[7].bco=' + scn_dis + '"]') } else if (Scene_Master.state == "Night") { HASP_Plate01_Plate_Command_JSON.sendCommand('["p[1].b[4].bco=' + scn_dis + '", "p[1].b[5].bco=' + scn_dis + '", "p[1].b[6].bco=' + scn_en + '", "p[1].b[7].bco=' + scn_dis + '"]') } else if (Scene_Master.state == "Bedtime") { HASP_Plate01_Plate_Command_JSON.sendCommand('["p[1].b[4].bco=' + scn_dis + '", "p[1].b[5].bco=' + scn_dis + '", "p[1].b[6].bco=' + scn_dis + '", "p[1].b[7].bco=' + scn_en + '"]') } end [/code] Note: I change the colour to a variable For control on the sitemap add [code] Switch item=Scene_Master mappings=[Morning="Morning", Evening="Evening", Night="Night", Bedtime="Bedtime"] [/code] When you change on the sitemap it also changes on the Nextion this means you can set the same scene from different devices. In a separate scene.rules file I have setup my rules like [code] rule "Set Morning Scene" when Item Scene_Master changed to "Morning" then // your logic here end [/code] After which, @rickitaly (Rick) added Hi guys thank you very much for your job it's really AMAZING! I am done with all the hw/firmware related stuff and i am now moving to OH configuration… now what is not clear at this point is: is there already a solution which includes mqtt2.4 and new status JSON handling? I saw that @pkhajanchi started already something but there is nothing updated, is it correct? If there is nothing i can start to have a look at it…(i dont have much time at the moment but sure i will share what i can do…) Let me know! To which @denominator (James Bowler) replied I just using the old mqtt binding. With JSON when you refresh too much stuff at once you see a flicker on the screen So @pkhajanchi (Pankaj) replied Latest 0.37 from from aderusha is not working for me… Tried pre-complied one and also compiling myself… But anyways, your firmware is working fine with JSON. So, using that only as of now… The good news is that I finally got time and upgraded OH configuration for mqtt2.4. It's working fine and was very easy to do after you implemented JSON paths. Many thanks to you. Sorry for the delay guys… Was busy with my work. @rickitaly @denominator Please find my attached things files and items files for mqtt2.4. No changes required in the rules files… Hope this helps… plate01.items.txt (3.6 KB) plate01.things.txt (1.6 KB) To which @pkhajanchi (Pankaj) replied I am using this mostly to toggle devices… So my next mission should be to update Item State to the Button text of HASP Plate. Rules like: On item state change, send json message to plate to change the button text and maybe also change it's color. @bartus (B K) replied James, good addition with the button highlights! That's definitely a nice improvement, especially for the “toggle” buttons on the HASP (to show whether the next button press will toggle ON or toggle OFF). For my scenes, they're really setpoints that get pushed to all different devices, so there's not really an “ON” state to any given scene (any device can be changed off the scene setting, and pressing the scene again, or selecting a new scene just sends the same or different set of setpoint commands). So @bartus (B K) replied pkhajanchi: > Rules like: On item state change, send json message to plate to change the button text and maybe also change it's color. Check out James's (@denominator) post above - he's already handled the rule for changing button background color based on state of the button. Thanks for the MQTT 2.4 changes! I'm wondering how to handle the repo updates. Since most users will still be using the MQTTv1 binding, I don't want to update the repo to these items/things files yet, I don't think. We'll wait til 2.5, when the v2 binding will get some additional fixes (including auto-discovery fixes). It'd be nice to maybe support the Homie protocol with this, but that's a change I'd need to make to the firmware itself (and push to aderusha's repo, as well). In other words, lots of great ideas and improvements to this going forward - just gotta find the time to make it all happen To which @denominator (James Bowler) replied Yes I set it up for one room to only have one scene you can always set them up individually. The firmware can be changed for the homie protocal but needs to be customizable through the webpage. Spec for homie 4 is HERE however because most of the data goes through json it would be different way of control. Eg why go from Nextion > MCU > MQTT JSON > OPENHAB > MQTT > SONOFF when you could go Nextion > MCU > MQTT > SONOFF Openhab would still pickup the state change if subscribed to mqtt. I currently have a enhanced nextion on order so I going to do NEXTION > LIGHT or FAN and still have NEXTION > MCU > MQTT then the network could be rooted and I can still use it as a light switch. Because I have some non-enhanced I may also do NEXTION > MCU IO relay. + MQTT After which, @denominator (James Bowler) added So because I like using all the features of a device I have played with the NEXTION system try this rule for me. [code] rule "Setup Nextion System Variables" 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 var jsonString = '["thsp=20", ' + // Setup Screen Sleep timer = in seconds '"wup=255", ' + // Sets which page Nextion loads when exiting sleep mode. When wup=255 it will wake up in the page it went to sleep in '"thup=1", ' + // Sets if Nextion should auto-wake from sleep when touch press occurs '"usup=0"]' // Sets if serial data wakes Nextion from sleep mode automatically (when you send any data to screen) HASP_Plate01_Plate_Command_JSON.sendCommand(jsonString) end [/code] @denominator (James Bowler) replied You can also send text, so you can have it display alarm or something. [code] rule "Send Message to SCREEN" when Item your_trigger received command ON then HASP_Plate01_Plate_Command_JSON.sendCommand('["sleep=0"]') // Wake up Nextion Thr8b7c:f320:99b9:690f:4595:cd17:293a:c069sleep(300) // Nextion needs time to wakeup yawn var jsonString = '["cls RED", ' + // Takeover Screen and turn red '"xstr 10,10,240,400,1,BLACK,RED,1,1,1,\\"All your base are belong to us\\""]' // Type Message on screen HASP_Plate01_Plate_Command_JSON.sendCommand(jsonString) end /* xstr Prints text on the Nextion device using defined area for text rendering usage: xstr <x>,<y>,<w>,<h>,<font>,<pco>,<bco>,<xcen>,<ycen>,<sta>,<text> <x> is the x coordinate of upper left corner of defined text area <y> is the y coordinate of upper left corner of defined text area <w> is the width of the defined text area <h> is the height of the defined text area <font> is the number of the Resource Font <pco> is the foreground color of text (Color Constant or 565 color value) <bco> is a) background color of text, or b) picid if <sta> is set to 0 or 2 <xcen> is the Horizontal Alignment (0 – left, 1 – centered, 2 – right) <ycen> is the Vertical Alignment (0 – top/upper, 1 – center, 3 – bottom/lower) <sta> is background Fill (0 – crop image, 1 – solid color, 2 – image, 3 – none) <text> is the string content (constant or .txt attribute), ie “China”, or va0.txt */ [/code] It will go away after sleep cycle or you change page So @crankycoder (Jason) replied has anyone else modified the screens? i would love to see some more screen examples. To which @denominator (James Bowler) replied 20190401_210537_HDR.jpg624×832 149 KB The top line is the outside weather Next inside weather and state of aircon (cool) After which, @Daveps (Dave) added I cannot get the pages to show on my LCD. The LCD shows the nodes IP address and that is connected to MQTT broker that is all. When opening in a browser the panel's IP address there is no option to select pages ? Have updated OTA successfully from browser and LCD showed QR code after first boot and see activity on serial when touching screen but no pages ! I have reflashed the nextion display as well as the D1 mini Any idea what could be going on ? Then @bartus (B K) said @Daveps \- two things I can think of: 1. Make sure you loaded all the rules, and are using the correct channels for your HASP, 2. Make sure you're seeing MQTT traffic on your broker from the HASP. @Daveps (Dave) replied Thanks Bartus, Got it sorted,now to customise my has plate ! So @Lspaula (Luciano De Paula) replied This unfortunately still did not work for me. `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` I think I have to properly learn how to manipulate with variables on Openhab. It is so hard! Sometimes I get myself trying it for hours with no success. If you could point some extra examples, it would be really appreciated. Then @denominator (James Bowler) said Did you get the default rules to work and get the screen working? Here is the doc for transformations Transformations Can you post your items and rule that you are having troble with or join us on discord https://discord.gg/XuwMaw To which @Lspaula (Luciano De Paula) replied Thak you for the fast reply. Yes, the plate is working ok. I am using the original HASP rules, provided at https://github.com/bkpsu/HASwitchPlate/tree/master/contrib/openHAB . I am able to toggle some switches an see the JSON replies. I have included the rule for the dimmer conversion as BK described (there is a missing closing “)”, on the second logInfo line, by the way), but could not get it to work as said earlier. My item has been declared as a String, just as on the original items file: > String HASP_Plate01_Plate_State_JSON_Value “HASP Plate 01 JSON State Value” (HASP) {mqtt="<[broker:hasp/plate01/state/json:state:JSONPATH($.value)]"} I get the error when this operation is carried out: > var Number adjust_incoming_dimmer_number = (incoming_dimmer_number*100/255).intValue I will also try Discord, but I ithink it would be great for someone else having the same problem as me to find the answer here. Perhaps creating a copy there would be appropriate? Regards, Luciano Then @denominator (James Bowler) said Easiest way is to change the scale in the Nextion editor Capture dimmer value.PNG1003×714 28.4 KB So @Lspaula (Luciano De Paula) replied At Discord you said that to do the math, I would have to convert it to float and then back to int. I am just astonished with the code overheat to accomplish such a simple task! Anyways, the solution on Nextion editor you proposed worked like a charm. Thank you very much. After which, @Lspaula (Luciano De Paula) added After editing using Nextion Editor v0.58, changing the layouts to suit my system, I have got this strange behaviour. A single touch of a light button does not change the state of a light, but changes it twice. For example, if the light is on, a single touch on the Nextion toggles it off and back on. Here are the debug messages for the original tft fie and for the modified version: Original TFT file: Off Sequence: > [+1360.595s] HMI IN: 0x65 0x1 0x6 0x1 0xff 0xff 0xff > [+1360.601s] HMI IN: [Button ON] ‘p[1].b[6]' > [+1360.606s] MQTT OUT: ‘hasp/plate01/state/p[1].b[6]' : ‘ON' > [+1360.836s] HMI IN: 0x65 0x1 0x6 0x0 0xff 0xff 0xff > [+1360.842s] HMI IN: [Button OFF] ‘p[1].b[6]' > [+1360.847s] MQTT OUT: ‘hasp/plate01/state/p[1].b[6]' : ‘OFF' > [+1360.854s] HMI OUT: ‘get p[1].b[6].val' > [+1360.864s] MQTT IN: ‘hasp/plate01/light/switch' : ‘ON' > [+1360.870s] HMI OUT: dim=dims > [+1360.886s] MQTT IN: ‘hasp/plate01/light/switch' : ‘ON' > [+1360.893s] HMI OUT: dim=dims > [+1360.909s] MQTT IN: ‘hasp/plate01/light/state' : ‘ON' > [+1360.937s] HMI IN: 0x1a 0xff 0xff 0xff > [+1360.942s] MQTT IN: ‘hasp/plate01/light/state' : ‘ON' On Sequence: > [+1419.076s] HMI IN: 0x65 0x1 0x6 0x1 0xff 0xff 0xff > [+1419.081s] HMI IN: [Button ON] ‘p[1].b[6]' > [+1419.086s] MQTT OUT: ‘hasp/plate01/state/p[1].b[6]' : ‘ON' > [+1419.272s] HMI IN: 0x65 0x1 0x6 0x0 0xff 0xff 0xff > [+1419.278s] HMI IN: [Button OFF] ‘p[1].b[6]' > [+1419.283s] MQTT OUT: ‘hasp/plate01/state/p[1].b[6]' : ‘OFF' > [+1419.290s] HMI OUT: ‘get p[1].b[6][0E]val' > [+1419.300s] MQTT IN: ‘hasp/plate01/light/switch' : ‘ON' > [+1419.307s] HMI OUT: dim=dims > [+1419.323s] MQTT IN: ‘hasp/plate01/light/switch' : ‘ON' > [+1419.330s] HMI OUT: dim=dims > [+1419.345s] MQTT IN: ‘hasp/plate01/light/state' : ‘ON' > [+1419.363s] MQTT IN: ‘hasp/plate01/light/state' : ‘ON' > [+1419.380s] HMI IN: 0x1a 0xff 0xff 0xff Modified version single touch (OFF and then ON) : > [+163.525s] HMI IN: 0x65 0x1 0x6 0x1 0xff 0xff 0xff > [+163.530s] HMI IN: [Button ON] ‘p[1].b[6]' > [+163.535s] MQTT OUT: ‘hasp/plate01/state/p[1].b[6]' :[00]‘ON' > [+163.649s] HMI IN: 0x65 0x1 0x6 0x0 0xff 0xff 0xff > [+163.655s] HMI IN: [Button OFF] ‘p[1].b[6]' > [+163.660s] MQTT OUT: ‘hasp/plate01/state/p[1].b[6]' : ‘OFF' > [+163.667s] HMI OUT: ‘get p[1].b[6].val' > [+163.694s] MQTT IN: ‘hasp/plate01/light/switch' : ‘ON' > [+163.701s] HMI OUT: dim=dims > [+163.716s] MQTT IN: ‘hasp/plate01/light/state' : ‘ON' > [+163.775s] HMI IN: 0x71 0x0 0x0 0x0 0x0 0xff 0xff 0xff > [+163.781s] HMI IN: [Int Return] ‘0' > [+163.800s] MQTT IN: ‘hasp/plate01/light/switch' : ‘ON' > [+163.806s] HMI OUT: dim=dims > [+163.842s] MQTT IN: ‘hasp/plate01/light/state' : ‘ON' > [+164.067s] MQTT IN: ‘hasp/plate01/light/switch' : ‘ON' > [+164.074s] HMI OUT: dim=dims > [+164.079s] MQTT IN: ‘hasp/plate01/light/switch' : ‘ON' > [+164.086s] HMI OUT: dim=dims > [+164.102s] MQTT IN: ‘hasp/plate01/light/state' : ‘ON' Do you guys think this would be related to some issue on the newer version of the Nextion Editor? It seems that a different command is being sent to the display. Am I missing some configuration. I based the new layout on the original one. @Lspaula (Luciano De Paula) replied Well. It turns out it was just the touch release event that was selected for all buttons on Nextion editor. After deselecting it, everything is working well. To which @Daveps (Dave) replied Please help with this rule,I have an LED dimmer working from the GUI and want my HAS Plate to control it also. The rule needs to scale from 0 to 255 from HAS plate to 0 to 100 for OH. > else if (eventbutton == ‘7') > { > //Insert action to perform if dimmer 1 was moved [code] if (HASP_Plate01_Plate_State_JSON_Value.state.toString != 'ON') { var Number lightVal = (HASP_Plate01_Plate_State_JSON_Value.state as DecimalType) lightVal = lightVal/2.55 sendCommand(LED_Strip0_dimmer, lightVal) } } [/code] I get the following error in log when moving the slider … > Blockquote[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Handle HASP Master': Could not cast 152 to org.eclipse.smarthome.core.library.types.DecimalType; line 347, column 55, length 56 lightVal is defined as a var at top of rules file Where is my mistake ? To which @bartus (B K) replied You say lightVal is defined at the top, but I see it defined right in the rule, so are you defining it twice? (you can remove the one on top). The error looks to me like you're mixing data types (something that's easy to do with openHAB, as there's lots of implicit and loosely defined types to go between). Without seeing the rest of the rule, my guess would be that you need to send the integer value from lightVal into the LED_Strip0_dimmer item (which is of type DimmerItem). So, change just the sendCommand line to: [code] sendCommand(LED_Strip0_dimmer, lightVal.intValue) [/code] Then @Daveps (Dave) said Hi Bartus, I removed the lightVal definition at the top of the rules file and made the change suggested with the same result in OH log. The rule above is complete for dimmer 1 on HASP page 4. > else if (eventbutton == ‘7') > { > //Insert action to perform if dimmer 1 was moved [code] if (HASP_Plate01_Plate_State_JSON_Value.state.toString != 'ON') { LED_Strip0_dimmer.sendCommand(HASP_Plate01_Plate_State_JSON_Value.state.toString) [/code] } The above rule works but needs to be divided by 2.55 for OH dimmer item. Anything else I could try ? After which, @Lspaula (Luciano De Paula) added People, for those willing to have a “fancier” HASP, I have developed a set of background images to be used with the original HASP software. I have commited everything to my GitHub repo, as well as some rules example for using it. Please check it out at https://github.com/lspaula/Nextion-background-for-HASwitchPlate Then @Devon_H (Devon Hills) said Ok I'm officially at a loss as to where to look here. I have a screen and board freshly flashed with the newest versions on github. Saved the rules, items, sitemap from github. Booted and setup the screen to connect. It gets a successful message, load the site map, and nothing changes on the screen nor does the site map update with the stats from plate01. I'm using openhab 2.4 with the embedded mqtt broker. I am able to use my 16relay mysensor mega setup and 5 of the 8 sonoff devices I'm setting up connect and send/receive messages. I'm not sure what I'm doing wrong. The only message I see relating to the plate01 in the log are the messages from site map changing and a notification when the plate connects saying no session. To which @bartus (B K) replied @Devon_H \- if you're using the Embedded broker, that means you're using the MQTTv2 binding. The items file I have in the first post is still written for MQTTv1 (which is what I'm using currently). I haven't had time to convert all of my MQTT devies to v2 yet, but fortunately, @pkhajanchi created a compatible set of .items & .things files in his post earlier this year. You should be able to use his configuration directly with my rules/sitemap entries. Once I have more time, I will convert my items (and update the top post with the V2 configuration). @Devon_H (Devon Hills) replied Oooh. I though I read that the new coding was uploaded to github already. Guess that would make sense. I will browse up and find the other code and plug it in to see what happens. Much appreciated. Edit: Took a little bit of messing around to get the broker set right… but we successfully have a screen and has buttons… now, let the fun begin. As soon as I'm done rewiring a pinsetter. Then @Simon_Thorsted (Simon Thorsted) said Hello Can you show how to make the plate send mqtt to a wled ,I have tried different things but i can not find were to change a dimmer mqtt masage to show up Clint_id : PIXEL_LED. I tried in
{'source': 'discourse', 'url': 'https://community.openhab.org/t/home-automation-switch-plate-hasp-diy-touch-controller/59682', 'title': 'Home Automation Switch Plate (HASP) - DIY touch controller', 'views': 10890, 'has_accepted_answer': False, 'word_count': 11210, 'like_count': 40, 'reply_count': 44, 'participant_count': 17, 'posts': 80, 'tags': 'touchscreen', 'author': '@bartus (B K)', 'participants': '@bartus (B K), @pkhajanchi (Pankaj), @denominator (James Bowler), @LukeCorkill (Luke Corkill), @Stewart-MyNerdLab (Stewart ), @SHP-Stewart (Stewart ), @ruangreeff (Ruan), @rickitaly (Rick), @crankycoder (Jason), @Daveps (Dave), @Lspaula (Luciano De Paula), @Devon_H (Devon Hills), @Simon_Thorsted (Simon Thorsted), @DigitalDB (C S), @milo (M), @stonke (Kristoph), @MaAnMa-manuel (MaAnMa)', 'image_url': ['//community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/optimized/3X/d/d/dd5194c287a3bb08abc90aec472786bea681b69b_2_1024x330.png'], 'created_at': '2018-12-13T12:05:13.190Z', 'last_posted_at': '2021-02-24T21:33:32.933Z'}