openHASP icon indicating copy to clipboard operation
openHASP copied to clipboard

add feature : object alias

Open marsman7 opened this issue 4 months ago • 4 comments

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 avatar Mar 24 '24 14:03 marsman7

I work again on this feature.

marsman7 avatar Mar 26 '24 09:03 marsman7

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...

fvanroie avatar Mar 27 '24 21:03 fvanroie

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 avatar Mar 28 '24 15:03 marsman7

Please review

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

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

marsman7 avatar Apr 06 '24 06:04 marsman7