HASwitchPlate / openHASP

HomeAutomation Switchplate based on lvgl for ESP32
https://www.openhasp.com
MIT License
726 stars 185 forks source link

add feature : object alias #688

Closed marsman7 closed 7 months ago

marsman7 commented 7 months ago

An alias can be assigned to each object. This means that the object can be accessed not only with the page number and ID (pXbY) but also by alias. The advantage of this is that the position of the object does not have to be known. For example, it is possible to change the status of a button on several plates with a single command via MQTT, even though the button has a different position on different plates. When using the alias, the command must be preceded by an '@', for example "@Alpha.text"

To be able to use alias, USE_OBJ_ALIAS must be greater than zero when compiling.

#define USE_OBJ_ALIAS 1

Example :

pages.jsonl

{"page":1,"comment":"---------- Page 1 ----------"}
{"id":0,"bg_color":"#000050","text_color":"#555555"}
{"page":1,"id":10,"obj":"label","x":10,"y":10,"w":120,"h":36,"text":"Red","text_font":24,"bg_color":"#ff0000","bg_opa":255,"radius":7,"align":"center","alias":"Alpha"}
{"page":1,"id":11,"obj":"label","x":10,"y":50,"w":120,"h":36,"text":"Green","text_font":24,"bg_color":"#00ff00","bg_opa":255,"radius":7,"align":"center","alias":"Bravo"}
{"page":1,"id":17,"obj":"btn","x":10,"y":200,"w":120,"h":70,"toggle":false,"text":"\uE05D","text_font":32,"bg_color":"#005000","alias":"Marsman","action": {"down": "@alpha.text example"}} 

MQTT :

Topic : hasp/plates/command/@bravo.bg_color Payload : #888800