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.
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).
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
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
So because I like using all the features of a device I have played with the NEXTION system try this rule for me.
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
You can also send text, so you can have it display alarm or something.
rule "Send Message to SCREEN"
when
Item your_trigger received command ON
then
HASP_Plate01_Plate_Command_JSON.sendCommand('["sleep=0"]') // Wake up Nextion
Thread::sleep(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
*/
It will go away after sleep cycle or you change page
has anyone else modified the screens? i would love to see some more screen examples.
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 ?
@Daveps - two things I can think of:
- Make sure you loaded all the rules, and are using the correct channels for your HASP,
- Make sure you’re seeing MQTT traffic on your broker from the HASP.
Thanks Bartus,
Got it sorted,now to customise my has plate !
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.
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
Thak you for the fast reply. Yes, the plate is working ok. I am using the original HASP rules, provided at HASwitchPlate/contrib/openHAB at master · bkpsu/HASwitchPlate · GitHub . 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
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 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.
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.
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
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)
}
}
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 ?
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:
sendCommand(LED_Strip0_dimmer, lightVal.intValue)