Exec node - trying to pass command to virtual environment

In my RPi environment I have a LIFX asyncio API within a virtual environment (menv) on RPi OS.
I can issue a terminal command as follows to activate the environment and then turn on lights:

source ~/menv/bin/activate && lifx lan:transform -- '{"power": "on", "color": "red"}'

This works, so I want to do this using an exec node. My hope was to put as much of the command into the nodes 'Command" field and pass in and add the rest. Since I have to activate the menv each time, I set the Command (it has a trailing space) to:

source ~/menv/bin/activate && lifx lan:transform -- 

I used another node to inject and :

'{"power": "on", "color": "green"}'

The resulting full stderr message is "/bin/bash: lan:transform: command not found" which would indicate the injected string needs to be escaped. I have tried to do this but have yet to succeed!

Any guidance would be appreciated.

Try this, before the exec node add a change node and put the command and all options as a string in msg.payload. In the exec node leave the Command option blank and check off the +Append _ msg.payload and see if that works.

Perhaps you meant leave Apend on/ - with it off it said "TypeError: The argument 'file' cannot be empty. Received ''.. I did set it on, and the error is now "/bin/bash: lan:transform: command not found"

Hmmm should have worded it 'Check the "Append _ msg.payload" option
Change node:

exec node
execnode

And I read it too quickly :slight_smile: Your screen shots mimic what I have, but here is the embarrassing part - you will notice that when I shifted the command to the change node I left out the "lifx" after the &&. Now it's there it works, so MANY thanks.

Could you explain what is different between creating the command(s) in the Change node, and building it the way I was doing? It would be nice to have some extra learning from the 2 days playing around! It will also help me as I expand the functionality.

The command/program to be executed needs to go into the ‘command’ option with no arguments. The arguments go in the Append. If you want to run multiple commands, passing them in msg .payload is the only way to do it.

Took me awhile to learn this too :wink:

all it does under the covers is join all the parts together separated by spaces then tries to execute it... so you can build it up fairly much any way you want... pass it all in as the append - use a command and append the parameters, use a command and some parameters and append some more. etc.

1 Like

This does not answer your original question but have you considered using node-red-contrib-node-lifx instead?

Disclaimer: I'm the maintainer of it (although it's not originally written by me) and also a co-maintainer of the underlying Node.js library.

1 Like

@ristomatti - I am in a bit of a 'learning mode' so I haven't tried that node yet. I have been focusing on using the recently announced photons-core library primarily because of its asyncio capabilities and the rich support it provides for animations of tiles and Z strips. That said, I will take a look, is there a particular underlying LIFX library that it uses? One area of interest is support for the new LIFX switches - I have 20 of them and the only current support is via the HTTP protocol which will not be fast enough for my 100+ lights.

Unfortunately the library lacks support for the animations and switches. The switches are currently only available in Australia if I'm right? Regardless they seemed quite pricey and required installation (not something I can do on a rental apartment) so we aren't likely adding support anytime soon unfortunately.

The node works very fast over the local network though and is likely a lot simpler to use with Node-RED than executing Python code. You might still want to consider trying it out for general light switching/color changes and just handle the animations/switches through the Python tools.

@zenofmud thanks, what you have given me has led to a working flow. It would seem 'change' has lot of potential but for now I am using a 'function' node to 'construct' my argument, passing this thru a 'change' node to cleanse it :slight_smile: and then on to the 'exec' node that appends it to the command/program part. @dceejay I need to really work on understanding the 'Change' node - I will work on getting past the fairly basic explanations I have found to date

Yes, that makes sense. I didn't realize the Switch was only available here. Installation is pretty easy, but you have to have a neutral as well as the active at the install location. I understand that there will be an API for the switch in a while but I am not sure I can wait for that. As you say, using the lifx node for the everyday switching might be the way to go - it has sufficient functionality for most things but I wonder - how do you get your inputs?
One real concern is connectivity - there are plenty of r/lifx posts that talk about lost connections. The need to 'reset' globes periodically might work when you have a small number, but in my case they are mainly down-lights so I have to group them into smaller logical groups that can be reset by a switch that is left on. Losing connection to one globe requires resetting the entire group! I will be using a very good meshed Wi-Fi system so perhaps this will not be as big an issue as I fear :slight_smile:

If by inputs you mean how do I control the lights, I am using a wireless wall switches from Milight/Miboxer (a Chinese home automation brand). I have built a custom bridge device using some hobbyist electronics components and a custom microcontroller firmware made for this purpose to convert the Milight protocol to something I can handle in NR. In addition I have some 433MHz wireless wall switches for basic on/off toggling of which signals I also get via a similar separate bridge (its also used for cheap door switches and motion sensors).

If you meant how do I get input of the light status, this is handled by the contrib node. It has both input node that send messages when a light changes state and output node for changing the state.

I almost never experience issues with the light connectivity myself but I've also read a lot of people having issues. Hopefully they'll work fine on your setup also! Resetting several lights behind a single switch would definitely be a huge PITA...

The Milight product set looks interesting, but I am a little over-invested in LIFX! Building a new house allows you to hide the extravagance. Yes, I did mean how you control the lights which you have covered. My current house has C-Bus which is even more expensive than LIFX. I plan to use a Hubitat for some of the other functions, most likely Ubiquiti for my Wi-Fi, and I am hoping that the RPi4 handles the NR traffic.

1 Like

(more off topic comments but LIFX discussions are so rare I'll just go with it)

I also have almost only LIFX lights (12 covering our apartment and 7 at our summer cottage). I can perfectly understand the wish to use the switches from the same company! In my case, I've had LIFX lights for maybe 7 years and most of that time I wished they'd release some kind of a switch (and particularly one that doesn't require installation).

Around 4 years ago I got tired of waiting and begun experimenting with 3rd party solutions. First I bought Flic Bluetooth LE based buttons linked through their Android app. It was not great as the button presses had to travel button -> phone app -> lifx cloud (Finland- US-Finland round-trip) -> bulb. The latency felt very unnatural and occasionally the lights dropped from cloud and had to be restarted. After some time Flic released Linux server software that could run on a Raspberry Pi and at that point I found Node-RED. This got rid almost all of the latency but the battery life of the Flic buttons turned out to be appalling lasting maybe 3 months.

Next Philips released a dimmer switch for their Hue products. I had a Hue hub (as I tried Hue bulbs at some point) and was able to hack it working using a Hue to MQTT bridge script I found from GitHub. It was a huge improvement as I was then able to dim the lights although there was some latency again as the Hue hub required polling of button state that couldn't be faster than 500ms so I never bought a second one.

My third finding was the Sonoff RF Bridge (flashes with Espurna firmware to get MQTT messaging) combined with 2 and 3 gang 433MHz switched resembling traditional light switches. They were cheap and robust enough to put them on every room. But I still had to reach for my phone if I wished to change the brightness/color/color temperature which was definitely not optimal.

Then I saw the Milight wall switches randomly on AliExpress having touch controls for all the parameters. After some googling I found out that someone had created an ESP8266 MQTT bridge firmware utilising NRF24L01 radios (both of which I had laying around). This combination (with Node-RED) has worked almost flawlessly for months now. The Milight switch panels are cheap and come as 4 and 8 gang models and in addition to those I've got couple of 8 gang remote controllers from them. :slightly_smiling_face:

Yes, the LIFX story has been fascinating. I jumped on board as part of the Kickstarter startup and purchased 45 globes for the house I was about to build. While I was waiting I tried to create room switches using small android touchscreen units I found while in the US but had to give up because the standby power was too high and I calculated the electricity cost would be prohibitive! Anyway the Kickstarter project ran late and I had to use some Phillips LED downlights which I controlled using C-Bus. Good but expensive and no color!

Installation of the LIFX switch is really no different to others, except of course you need a neutral and active at the switch. I think the ‘installation’ talk is really about safety and regulations and not wanting DIY people to create legal hassles. Mind you, apartment installation would have it’s own issues. The current Switch firmware is cloud based, no direct Switch to bulb support. I understand that a LAN update will come. Another current limitation is that the switch itself only has one MAC address and more work is required there.

I also grabbed some flic units for the new house – but have yet to use them. Battery life is always an issue for me but I do have some uses for them and could most likely live with the cloud constraint.

I guess my ‘LIFX affliction’ comes from the early Kickstarter process – there were lots of doubters and I admired the teams perseverance. :blush: And I still have my ‘Gen 1’ bulbs to use up. I am of a fan of cloud based control and correct or not, I associate many of the disconnects with it.

My Node-RED discovery was a few months back as I was looking at the Hubitat HA system and found a number of their users offloading their LIFX control to RPis. I am hopeful my RPi4 will be up to the task, if not I will go to a NUC or similar.

Your Milight experience is intriguing and depending on the cost I might take a look at how they fit in with my ideas. A quick look at the AliExpress site makes it appear feasible.

So, thanks for the insights, and keep well in these weird times!

Alan Williamson

Victoria, Australia

2F0D69C78C454067B142C5ECB3B11BA7.jpg

2 Likes

No doubt the installation is simple but here in Finland it's required by the law to have a licensed electrician do any "permanent" installation. In a rental apartment in my case would also require me to first get a permission from the landlord, and then have then uninstalled before moving out. If I owned the apartment it would be a different story. :slightly_smiling_face:

If you're having any disconnection issues it is very likely the cloud connection dropping and not resuming before a power cycle. The LAN protocol is a lot more robust and near instant to respond.

Keep well you too!

Yes, same regulatory and apartment related issues here. I actually own an apartment and If my tenant put in LIFX switches I would just insist they leave them in if/when they leave :blush:

Yes, my new house will have a good mesh Wi-Fi, possibly Ubiquiti.

As they just use mains for power, could you just mount them in a moulded box plugged in via a normal socket ? Not as neat as wall mount obviously but could certainly be attached to (say) a bedside cabinet etc.

Well sure but for instance there's 0 electrical outlets in our apartment entrance room. But for me the issue is already solved with these Page Not Found - Aliexpress.com

The B8 controller has a nice glass finish and works over 2.4GHz (proprietary protocol) super well. It's also a fraction of the cost of the less featured LIFX wall switch (which even isn't available here yet). :slight_smile:

You might find this post interesting while having such a huge amount of WiFi bulbs: Ultimate LIFX house - Using LIFX - LIFX Developer Zone Ultimate LIFX house - #6 by russb - Using LIFX - LIFX Developer Zone. This guy seems to have gone to quite extremes but there's a lot of tips in case you run into issues.

Edit: in case someone gets curious about the NR setup, it's based on this ESP8266 firmware: GitHub - sidoh/esp8266_milight_hub: Replacement for a Milight/LimitlessLED hub hosted on an ESP8266