HASwitchPlate / openHASP

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

add feature : object alias #689

Open marsman7 opened 6 months ago

marsman7 commented 6 months ago

Object alias

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":245,"y":200,"w":75,"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

marsman7 commented 6 months ago

I work again on this feature.

fvanroie commented 6 months ago

I don't think using SDBM for storing a hash of user defined alias names is the right way to go... Please add your view to the discussion here as there are multiple views to achieve this.

I think the alias should be reversible, so needs to be stored. It can also impact the event which are send out to pXbY topics now, but maybe should also use the alias if set. What about multiple objects with the same alias etc...

marsman7 commented 6 months ago

Yes, I've already thought about that. I'm working on extending that. I would then like to save the hash and the string.

A check as to whether the hash already exists will also be added. However, the question is what should happen if the hash already exists? Just display an error message?

Further discussion here: https://github.com/HASwitchPlate/openHASP/issues/365

marsman7 commented 5 months ago

Please review

warning for duplicate removed - Does not run reliably and leads to problems when starting openHasp

https://github.com/HASwitchPlate/openHASP/issues/365