flic / node-red-contrib-hal2

A set of nodes to help with basic home automation logic
2 stars 1 forks source link

Add support to copy hal2ThingType or templating. #3

Closed alexsahka closed 2 years ago

alexsahka commented 2 years ago

Add support to copy hal2ThingType to a new hal2ThingType and rename it later. (instead of creating new) Or support for templating. The idea is this: create one huge template one time with all possible Ingress / Egress Functions, then copy to new hal2ThingType and custom name it, then delete unused Ingress / Egress Functions.

Maybe I'm lazy, but I just created 5-6 different types of hal2ThingType, and it is not convenient to go back and copy different Ingress / Egress Functions.

Again this is just convenience.

Thank you for your work!

flic commented 2 years ago

Yeah, totally with you on this one. My plan is to use the built-in library function in Node-RED, the same one that's used in the Template and Function nodes, but I haven't figured out how it works yet.

flic commented 2 years ago

I'm not 100% satisfied with this solution and it most definitely doesn't solve the whole use case, but as a stop gap solution it's now possible to import functions from other types in v1.2.0:

Skärmavbild 2021-12-25 kl  13 52 16

Skärmavbild 2021-12-25 kl  13 52 52

alexsahka commented 2 years ago

Thank you! The copy function works, maybe there is a better way, but this is way easier than copying manually.

flic commented 2 years ago

Well, it took some time (and it's a bit of a hack to be honest, don't look under the covers! ;) ) but now it's possible to create templates of Thingtypes using the Node-RED Library function!

Skärmavbild 2022-04-16 kl  13 12 23 .

New functionality in v1.10.0.

alexsahka commented 2 years ago

I got this error when I tried to save the node to a Library. image

"Error saving library entry 'Control.template': TypeError: Cannot read property 'replace' of null"

Running Node-red (v2.2.0) in Docker, non Privileged mode. Permission error?

flic commented 2 years ago

Could be, but I've been testing it in non privileged docker. I'm guessing I've missed something. Can you post a copy of the Thing here?

alexsahka commented 2 years ago

[{"id":"ab3b33e7a16514bd","type":"hal2Thing","z":"ae7a451615589173","eventHandler":"27dbb6a92633ac81","thingType":"5189f948432bbb2e","name":"GH CONTROL ","attributes":[],"topicFilter":"","topicFilterType":"mqtt","topicPrefix":"","notes":"","outputs":0,"x":830,"y":20,"wires":[]},{"id":"27dbb6a92633ac81","type":"hal2EventHandler","name":"Control","maxlisteners":"50","heartbeat":"3600"},{"id":"5189f948432bbb2e","type":"hal2ThingType","name":"Control","contextStore":"file","nodestatus":"🌡️ TopDin %Temp Top Dinamics% GH Thermostat OilHeat♨️%GH OilHeat% Fan Barrel West %Fan Barrel West% Fan Barrel East %Fan Barrel East% Oil Heater♨️%Oil Heater% Top Fan %Top Fan% GH Window FAN %GH Window FAN%","items":[{"name":"Fan Barrel West","id":"8b67a03e.c33bf","topicFilterType":"StrEnd","topicFilterValue":"gh/west/barrel/fan","topicSuffix":"","type":"status","ingress":"873acccf.72275","egress":"ae559c21.ec7b9","notes":"","output":"1"},{"name":"Temp Top Dinamics","id":"a0b55f9d.f3772","topicFilterType":"StrEnd","topicFilterValue":"/nono/","topicSuffix":"","type":"status","ingress":"873acccf.72275","egress":"ae559c21.ec7b9","notes":"","output":"1"},{"name":"GH Thermostat OilHeat","id":"3f7c73d9.97d9fc","topicFilterType":"StrEnd","topicFilterValue":"/nono/","topicSuffix":"","type":"status","ingress":"873acccf.72275","egress":"ae559c21.ec7b9","notes":"","output":"1"},{"name":"Fan Barrel East","id":"326ebac3.f318b6","topicFilterType":"StrEnd","topicFilterValue":"gh/east/barrel/fan","topicSuffix":"","type":"status","ingress":"873acccf.72275","egress":"ae559c21.ec7b9","notes":"","output":"1"},{"name":"Oil Heater","id":"f8948cc.2052f7","topicFilterType":"StrEnd","topicFilterValue":"gh/oil/heater","topicSuffix":"","type":"status","ingress":"873acccf.72275","egress":"ae559c21.ec7b9","notes":"","output":"1"},{"name":"Top Fan","id":"9e0ed8c3.f06e18","topicFilterType":"StrEnd","topicFilterValue":"gh/top/fan","topicSuffix":"","type":"status","ingress":"873acccf.72275","egress":"ae559c21.ec7b9","notes":"","output":"1"},{"name":"GH Window FAN","id":"a8e3221.fbe18e","topicFilterType":"StrEnd","topicFilterValue":"gh/window/fan","topicSuffix":"","type":"status","ingress":"873acccf.72275","egress":"ae559c21.ec7b9","notes":"","output":"1"}],"attributes":[],"ingress":[{"name":"Pass-through","id":"873acccf.72275","fn":"// msg & attribute objects are\n// passed to function\n\nreturn msg.payload;"},{"name":"Convert to Number","id":"8ee1a390.26a8f","fn":"// msg & attribute objects are\n// passed to function\n\nmsg.payload = Number(msg.payload);\nreturn msg.payload;"},{"name":"Convert to Boolean","id":"30790874.144ee8","fn":"// msg & attribute objects are\n// passed to function\n\nmsg.payload = (msg.payload === 'true');\nreturn msg.payload;"}],"egress":[{"name":"Pass-through","id":"ae559c21.ec7b9","fn":"// msg & attribute objects are\n// passed to function\n\nreturn msg;"}],"thingStatus":true,"thingCommand":false,"thingOutput":false,"hbCheck":false,"hbType":"lwt","hbTTL":"","hbFilterVal":"","hbFilterType":"str","filterFunction":"0","outputs":"1"}]

alexsahka commented 2 years ago

For some reason, I cant export/import some nodes completely.

image

flic commented 2 years ago

Yeah, I'm getting the same error as you. Debugging...

flic commented 2 years ago

I think I found it, the export function couldn't handle when the Check alive ingress selection box was empty. Try 1.10.2 and see of it works better for you.

alexsahka commented 2 years ago

Now works with NodeRed v2.2.0, but doesn't work with v2.0.4. But this is just observation. Must be updated.

This option will make life a lot easier.

Thank you!

flic commented 2 years ago

Good to know, thanks!