mitch7391 / homebridge-cmd4-AdvantageAir

Catered shell script to integrate air conditioner control units by Advantage Air into HomeKit using the plug-in homebridge-cmd4.
MIT License
38 stars 5 forks source link

[Support] "Check configuration" error: jq is required globally and not installed. #68

Closed clabell77 closed 1 year ago

clabell77 commented 1 year ago

After following the instructions and clicking "Check Configuration", I get the error: "jq is required globally and not installed."

This is despite jq (I think?) being installed successfully:

user@computer ~ % which -a jq
/opt/homebrew/bin/jq
user@computer  ~ % echo '{ "name":"John", "age":31, "city":"New York" }' | jq .
{
  "name": "John",
  "age": 31,
  "city": "New York"
}
user@computer  ~ % jq -V            
jq-1.6

It's possible that I've messed up the Cmd4 config (I'm not actually sure what I'm supposed to add to it?) Cmd4 Config:

{
    "platform": "Cmd4",
    "name": "Cmd4"
}

Advantage Air System:

Homebridge Environment:

mitch7391 commented 1 year ago

Hi @clabell77, let’s see if we can get you sorted :) can you confirm which command you used to install jq?

Also lucky for you today’s rollout includes a new feature that creates your cmd4 config for you! We can get to that after we have jq sorted though.

clabell77 commented 1 year ago

Thanks @mitch7391 !

I've installed jq every which way (without success) - but most recently (and initially) I did it via brew (this was a re-install, obviously):

user@computer ~ % brew reinstall jq
==> Downloading https://ghcr.io/v2/homebrew/core/jq/manifests/1.6-1
Already downloaded: /Users/user/Library/Caches/Homebrew/downloads/fc2724606b6ebef1ba0db7d7ae84cfca1df8cfed9e58e3a8714413b3676935f7--jq-1.6-1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/jq/blobs/sha256:f70e1ae8df182b2
Already downloaded: /Users/user/Library/Caches/Homebrew/downloads/aea2d2833753ec3beb81e91decae79cfc2a6217a4a1589bb90f2bb3b14ea8bc8--jq--1.6.arm64_monterey.bottle.1.tar.gz
==> Reinstalling jq 
==> Pouring jq--1.6.arm64_monterey.bottle.1.tar.gz
🍺  /opt/homebrew/Cellar/jq/1.6: 18 files, 1.2MB
==> Running `brew cleanup jq`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

And actually - I now realise you probably meant my advantage air cmd4 config - which is currently something of a placeholder (I was very excited when I saw that you'd added the "auto-config" feature!):

{
    "platform": "cmd4AdvantageAir",
    "name": "Cmd4",
    "outputConstants": false,
    "statusMsg": true,
    "timeout": 60000,
    "stateChangeResponseTime": 0,
    "constants": [
        {
            "key": "${IP}",
            "value": "192.168.1.4"
        }
    ],
    "queueTypes": [
        {
            "queue": "A",
            "queueType": "WoRm2"
        }
    ],
    "accessories": [
        {
            "type": "Switch",
            "displayName": "Hallway",
            "on": "FALSE",
            "name": "Hallway",
            "manufacturer": "Advantage Air Australia",
            "model": "Daikin",
            "serialNumber": "Daikin",
            "queue": "A",
            "polling": true,
            "state_cmd": "'/usr/local/lib/node_modules/homebridge-cmd4-advantageair/AdvAir.sh'",
            "state_cmd_suffix": "z01 ${IP}"
        }
    ]
}
mitch7391 commented 1 year ago

Sorry for the delay @clabell77, just had to sort out dinner.

My fellow dev pointed out to me that this issue happened before for other users and we resolve it by moving jq to the folder where it should have been installed. Can you please run the following command?

sudo cp /opt/homebrew/Cellar/jq/1.6/bin/jq /usr/local/bin/

I am not sure why for some people it does not install in the right directory. Try the shell check again and see if that gets rid of the error you were seeing, you will no doubt get to a point where you see some errors for the config itself.

And actually - I now realise you probably meant my advantage air cmd4 config - which is currently something of a placeholder (I was very excited when I saw that you'd added the "auto-config" feature!):

The config you have shared above is not actually supposed to go in the config for homebridge-cmd4-advantageair, it is just supposed to go in homebridge-cmd4's config section. So before you run the new ConfigCreator, you might want to change "platform" back to "Cmd4" for the time being as it might affect the ConfigCreator by not overwriting what you have already put there.

clabell77 commented 1 year ago

Hi @mitch7391 - thank you so much for your help with this.

Copying jq to /usr/local/bin cleared the issue with check config (thanks!)

I had some issues with the auto-config script (errors when running it using the instructions - but worked around by running ./ConfigCreator.sh "192.168.1.4" directly.

It appears to have done a pretty good job - although I'll probably need to do some manual editing.

Really appreciate the help - didn't expect you to get in touch so quickly.

ztalbot2000 commented 1 year ago

Hi,

jq may be installed, but it must be in your path. Try which jq the path you specify '/pt/hmebrew/bin/jq is non standard. I'd be surprised if it was actually installed there.

On OSX (My computer), jq is installed via brew or MacPorts which would certainly not put it there but in some directory of /usr/local or /opt/local and would be put in your path.

Ttyl, John

On Tue, Aug 2, 2022 at 6:27 AM clabell77 @.***> wrote:

After following the instructions and clicking "Check Configuration", I get the error: "jq is required globally and not installed."

This is despite jq (I think?) being installed successfully:

@. ~ % which -a jq /opt/homebrew/bin/jq @. ~ % echo '{ "name":"John", "age":31, "city":"New York" }' | jq . { "name": "John", "age": 31, "city": "New York" } @.*** ~ % jq -V jq-1.6

It's possible that I've messed up the Cmd4 config (I'm not actually sure what I'm supposed to add to it?) Cmd4 Config:

{ "platform": "Cmd4", "name": "Cmd4" }

Advantage Air System:

  • Control Unit: MyPlace
  • Temperature Sensors: Yes

Homebridge Environment:

  • Node.js Version: v16.14.2
  • NPM Version: 8.5.0
  • Homebridge Version: homebridge-config-ui-x v4.50.0
  • homebridge-cmd4 Version: homebridge-cmd4 v6.3.0
  • homebridge-cmd4-AdvantageAir Version: homebridge-cmd4-advantageair v3.5.0
  • Operating System: macOS Monterey

— Reply to this email directly, view it on GitHub https://github.com/mitch7391/homebridge-cmd4-AdvantageAir/issues/68, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX3RMVR6YR2NGDJZ5TLVXDZZNANCNFSM55KTUAPA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

clabell77 commented 1 year ago

Hi @ztalbot2000

Installed using brew - not sure why, but that's where it installed it:

user@computer homebridge-cmd4-advantageair % which jq               
/opt/homebrew/bin/jq

Copying it to /usr/local/bin fixed the issue, though (I'm also using macOS v12.5)

mitch7391 commented 1 year ago

Hi @mitch7391 - thank you so much for your help with this.

No worries, always feel free to submit issues for questions, problems or suggestions :) glad you got it working in the end!

I had some issues with the auto-config script (errors when running it using the instructions - but worked around by running ./ConfigCreator.sh "192.168.1.4" directly.

Is there any chance you can try to repeat and capture these issues for us? Just so we can iron out any kinks that might still be there that we have missed. Three of us have been testing this privately for a few weeks leading up to the release.

It appears to have done a pretty good job - although I'll probably need to do some manual editing.

For most people what the ConfigCreator crafts will be good enough, but if you read through the Wiki you can really start to edit what you do or don't want in there! You could just have the Thermostat if you wanted...

Hi, jq may be installed, but it must be in your path. Try which jq the path you specify '/pt/hmebrew/bin/jq is non standard. I'd be surprised if it was actually installed there.

On OSX (My computer), jq is installed via brew or MacPorts which would certainly not put it there but in some directory of /usr/local or /opt/local and would be put in your path.

Ttyl, John

Also thanks for the feedback John, sounds like maybe an issue developed from trying multiple ways of installing jq then :)

clabell77 commented 1 year ago

Hi @mitch7391

The error I got running $config was:

user@computer .homebridge % $config
zsh: no such file or directory: /usr/local/lib/node_modules/homebridge-cmd4-advantageair/ConfigCreator.sh\n/System/Volumes/Data/usr/local/lib/node_modules/homebridge-cmd4-advantageair/ConfigCreator.sh

I confirmed that the script did actually exist here:

/usr/local/lib/node_modules/homebridge-cmd4-advantageair/

Then I had a quick look at the script and ran it directly.

Also of interest was the fact that in running the initial config command (config=$(find / -name 'ConfigCreator.sh' 2>&1 | grep -v find | grep node_modules)) my Mac prompted me to allow terminal access to photos, contacts, documents etc. (presumably because the find was running from root? But slightly disconcerting). It still worked even when I denied access to those things.

mitch7391 commented 1 year ago

Thanks for reporting this @clabell77, while my wife does have a mac and I started learning to use it a while back to make sure the install instructions worked for mac users, I have not tested the new ConfigCreator on a mac myself (only on my RPi through windows terminal). I cannot speak for why it would ask for these permissions; if you look through the script as you have done, you can there is nothing malicious in there, but I can see how it would take you aback.

@uswong have you experienced the above or can explain what may be going on..?

uswong commented 1 year ago

Hey guys, looking at what @clabell77 has reported made me realized that the find command on Mac always has /System/Volume/Data as root directory. Both files found by the find command is pointing to the exact same file.

The config=$(find / -name 'ConfigCreator.sh' 2>&1 | grep -v find | grep node_modules) is meant for the first time users who do not know where the script was installed. For Mac users, the command should be improved as follow:

config=$(find / -name 'ConfigCreator.sh' 2>&1 | grep -v find | grep node_modules | grep -v System)

if you know where the script is installed then just do it directly is the better option as you guys have done already.

It is always better to run it in your home directory or any directory where you have a write permission as they are a few temporary intermediate files written and removed in the process.

Another point for Mac users is that if you choose to allow the script to copy the created Cmd4 config to Homebridge config.json, you will be asked at some point to be allowed to access certain folders etc - it is not malicious and not doing any harm to say yes (it is also fine to deny access to photos, contacts, documents etc) as the script is merely looking for the location of Homebridge config.json using the find command. Once the script has found the location of Homebridge config.json, Mac users will be asked for the password, this is to allow the script to copy the created Cmd4 config to Homebridge config.json.

For all RPi/linux users, the sudo is sufficient to bypass the user input while running the script. That is why the RPi/linux users will not experience what Mac users are experiencing.

Hope this helps.

Please feel free to ask if you have any further questions or any clarifications required.

ztalbot2000 commented 1 year ago

Hi all,

You should never use find in any tool. I have 16 Terabytes on my Mac and if I found out that you were doing a find I'd scream. A command is either n your PATH or not. A tool is either installed in the proper paths ( machine dependent ) or not. Looking through everything is an extreme No No and highly intensive.

Ttyl, John

On Wed, Aug 3, 2022 at 6:40 AM uswong @.***> wrote:

Hey guys, looking at what @clabell77 https://github.com/clabell77 has reported made me realized that the find command on Mac always has /System/Volume/Data as root directory. Both files found by the find command is pointing to the exact same file.

The config=$(find / -name 'ConfigCreator.sh' 2>&1 | grep -v find | grep node_modules) is meant for the first time users who do not know where the script was installed. For Mac users, the command should be improved as follow:

config=$(find / -name 'ConfigCreator.sh' 2>&1 | grep -v find | grep node_modules | grep -v System)

if you know where the script is installed then just do it directly is the better option as you guys have done already.

It is always better to run it in your home directory or any directory where you have a write permission as they are a few temporary intermediate files written and removed in the process.

Another point for Mac users is that if you choose to allow the script to copy the created Cmd4 config to Homebridge config.json, you will be asked at some point to be allowed to access certain folders etc - it is not malicious and not doing any harm to say yes as the script is merely looking for the location of Homebridge config.json using the find command. Once the script has found the location of Homebridge config.json, Mac users will be asked for the password, this is to allow the script to copy the created script to Homebridge config.json.

For all RPi/linux users, the sudo is sufficient to bypass the user input while running the script. That is why the RPi/linux users will not experience what Mac users are experiencing.

Hope this helps.

Please feel free to ask if you have any further questions or any clarifications required.

— Reply to this email directly, view it on GitHub https://github.com/mitch7391/homebridge-cmd4-AdvantageAir/issues/68#issuecomment-1203778748, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX2BQIBERQOP2EOD6LDVXJEALANCNFSM55KTUAPA . You are receiving this because you were mentioned.Message ID: @.***>

uswong commented 1 year ago

Thanks for the comment John! I did not like find neither, it is very intensive.

I think cmd4-advantageair is always installed in /use/local/lib/node_modules/homebridge-cmd4-advantageair/. At least it is for RPi and Mac.

ztalbot2000 commented 1 year ago

Hi,

You cannot guarantee that. The check installation button has a routine for node_modules called getGlobalNodeModulesPathForFile because node_modules was not where it should be. The answer was supposed to be from the command 'npm root -g'., but that was not always the case as a number of issues arose. Use getGlobalNodeModulesPathForFile routine in your new tool. It has proven to be accurate.

My 16TB is also an NFS mounted NAS, you would also kill my network. I'm also having issues with multiple Time Machine mounts to 'Volumes so you would be searching there as well. (not your issue)

As for jq being moved to /usr/local/bin that solved the issue. The issue was not solved correctly as his PATH needs to be corrected to add '/opt/homebrew/bin' and that PATH would be system wide so that everyone could find jq

Ttyl, John

On Wed, Aug 3, 2022 at 8:37 AM uswong @.***> wrote:

Thanks for the comment John! I did not like find neither, it is very intensive.

I think cmd4-advantageair is always installed in /use/local/lib/node_modules/homebridge-cmd4-advantageair/. At least it is for RPi and Mac.

— Reply to this email directly, view it on GitHub https://github.com/mitch7391/homebridge-cmd4-AdvantageAir/issues/68#issuecomment-1203893981, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX5SMII7LIWGZOXHGQDVXJRXXANCNFSM55KTUAPA . You are receiving this because you were mentioned.Message ID: @.***>

mitch7391 commented 1 year ago

You cannot guarantee that. The check installation button has a routine for node_modules called getGlobalNodeModulesPathForFile because node_modules was not where it should be. The answer was supposed to be from the command 'npm root -g'., but that was not always the case as a number of issues arose. Use getGlobalNodeModulesPathForFile routine in your new tool. It has proven to be accurate.

Thanks for raising these concerns John! These are good points and you have given us an idea to work with. The end goal idea of the ConfigCreator is to have it launch from the Homebridge UI like the Config Check does. Ung Sing and myself are not super stars at JavaScript yet (speaking mostly for myself here) and will need to spend the time working out the nitty gritty of how you did the Config Check button. I imagine we couldn’t use the function you mentioned unless the ConfigCreator is in JavaScript?

uswong commented 1 year ago

Ung Sing and myself are not super stars at JavaScript yet (speaking mostly for myself here)

haha.. I have near no experience in JavaScript coding! I am just a self-taught amateur in bash scripting!

The end goal idea of the ConfigCreator is to have it launch from the Homebridge UI like the Config Check does.

I think this is where the JohnT's expertise can be leveraged!

Based on a bit of research I have done lately, bash script is possible to be run from a JavaScript. John, do you think that will work within the Homebridge-ui environment? If so, John, will you be able to at least get us started by putting together a framework with a ConfigCreator button which will trigger a JavaScript which in term will execute the bash script?

It is only in Homebridge-ui environment that we have access to getGlobalNodeModulesPathForFile, homebridgeConfigPath routines. Both paths are essential in making the running the "ConfigCreator.sh" faster and simpler.

ztalbot2000 commented 1 year ago

Hi Mitch,

If your going to try and run shell scripts, within homebridge-up, while you can, integrating it properly to be able to use the pop up dialog for error messages or user feedback will be extremely messy. Also, homebridge-ui does not have access to the users file system as you are within a cgi-script. That is why homebridge-ui is broken into two parts, server.js and the javascript that runs from the public web page of index.html. Yup, it would definitely be messy. Not what I would do.

Ttyl, John

Sent from Zarf’s iPad Air 2

On Aug 4, 2022, at 8:36 AM, uswong @.***> wrote:

 Ung Sing and myself are not super stars at JavaScript yet (speaking mostly for myself here)

haha.. I have near no experience in JavaScript coding! I am just a self-taught amateur in bash scripting!

The end goal idea of the ConfigCreator is to have it launch from the Homebridge UI like the Config Check does.

I think this is where the JohnT's expertise can be leveraged!

Based on a bit of research I have done lately, bash script is possible to be run from a JavaScript. John, do you think that will that work within the Homebridge-ui environment? If so, John, will you be able to at least get us started by putting together a framework with a ConfigCreator button which will trigger a JavaScript which in term will execute the bash script?

It is only in Homebridge-ui environment that we have access to getGlobalNodeModulesPathForFile, homebridgeConfigPath routines. Both paths are essential in making the running the "ConfigCreator.sh" faster and simpler.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

ztalbot2000 commented 1 year ago

Hi Mitch,

Yes, that routine is in Javascript. You could change it to a shell script, but as you have found out, she'll scripts are limited and not always portable. Javascript is really easy and remember all scripting languages have the same general constructs. It is not like you are suddenly writing in hieroglyphics. The last time I took a course for a programming language was back in high school, 50 years ago, and everything is still the same really. AdvAir could also be Javascript . I think we talked about that once. Oh well.

Ttyl, John

On Wed, Aug 3, 2022 at 10:45 PM Mitch Williams @.***> wrote:

You cannot guarantee that. The check installation button has a routine for node_modules called getGlobalNodeModulesPathForFile because node_modules was not where it should be. The answer was supposed to be from the command 'npm root -g'., but that was not always the case as a number of issues arose. Use getGlobalNodeModulesPathForFile routine in your new tool. It has proven to be accurate.

Thanks for raising these concerns John! These are good points and you have given us an idea to work with. The end goal idea of the ConfigCreator is to have it launch from the Homebridge UI like the Config Check does. Ung Sing and myself are not super stars at JavaScript yet (speaking mostly for myself here) and will need to spend the time working out the nitty gritty of how you did the Config Check button. I imagine we couldn’t use the function you mentioned unless the ConfigCreator is in JavaScript?

— Reply to this email directly, view it on GitHub https://github.com/mitch7391/homebridge-cmd4-AdvantageAir/issues/68#issuecomment-1204692634, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX6GKGGO3QDNKKLO7P3VXMVDRANCNFSM55KTUAPA . You are receiving this because you were mentioned.Message ID: @.***>

mitch7391 commented 1 year ago

Hey @ztalbot2000, we managed to get a solution going in the end that works very well :) @uswong was able to spend a bit of time figuring how to do what we needed in JS and we went forward with the solution!

Converting AdvAir over to JS would one day be part of an improvement to make this plugin its own stand-alone plugin; but life is too busy these days!