HA not able to find or run Curl command?

So the answer is no. You are not running a Core install you are running a Home Assistant OS install. This is your issue:

https://community.home-assistant.io/t/sshing-from-a-command-line-sensor-or-shell-command/258731

See here for a solution:

Hi Tom,

actually to be more specific it’s a Supervised install as the base OS is Arch Linux which I need for it’s various capabilities… (It is an “unsupported system”)

I have read through the posting and tested:

 docker exec -it homeassistant bash

gets me into the /config directory of HA…

I then tried my Curl command and it works fine:

curl -s http://x.x.x.x/api/xdevices.json?Get=XTHL | grep THL1-TEMP | cut -d : -f 2 | cut -d , -f 1 |  tr -d [:space:]

The output of the sensor is given:

9.65

I’m a little lost here… from what is written does this mean that I have to basically SSH into the same system from a command then run the same Curl command through SSH?

But if Curl isn’t running through the config.yaml file what’s to say that SSH will?

I can test it of course but I think it might just be easier to write a shell script and push the data to HA via the API then to have to do an:

ssh [email protected] -i keyfile 'command'

I’m not sure… what broke or changed post version 2023.11??

Hmm… ok so one solution was to run something like this taken from one of the comments:

- platform: command_line
  switches:
    rpi_screen:
      command_off: "ssh .... "

I doubt the ‘ssh’ command will run though as currently neither ‘cat’ or ‘curl’ commands are running but I will play around with it tomorrow and test…

Then you are running an unsupported system. The only OS that can be used for a Supervised install is Debian.

1 Like

Then you are indeed exactly in the same condition as the command_line.

You didn’t detail what “not working” is. What the symptoms? Nothing in the log?

Hi koying,

nothing is showing up in the logs at all… to be more precise: nothing regarding this issue is showing up as the logs are showing many other things

I have the logging set to ‘debug’ in config.yaml:

logger:
  default: info
  logs:
    custom_components.hacs: debug
    hacs: debug
    queueman: debug
    AIOGitHubAPI: debug
    

As to what is not working exactly… I am not seeing any of my ‘sensors’ or ‘switches’ appearing in the HA system as ‘Entities’ at all

I gave an example above of the “Outdoor Temperature sensor”

  • This does not show up in the /developer-tools/state tab at all

I have also got many switches configured in the ‘configuration.yaml’ file… again of which none are showing up?

To show an example from the “end user side” - In one of my panels I have this snippet of config:

              - cards:
                  - entity: switch.lounge_tv
                    hold_action:
                      action: more-info
                    name: Lounge TV
                    show_icon: true
                    show_name: true
                    state:
                      - color: green
                        icon: mdi:television
                        name: TV On
                        value: 'on'
                      - color: gray
                        icon: mdi:television-off
                        name: TV Off
                        value: 'off'
                    state_color: true
                    styles:
                      card:
                        - height: 100px
                    tap_action:
                      action: toggle
                    type: custom:button-card
                  - color: blue
                    color_type: icon
                    entity: script.htpc4_kr_vol_down
                    hold_action:
                      action: more-info
                    icon: hass:volume-minus
                    name: Decrease Volume
                    show_icon: true
                    show_name: true
                    styles:
                      card:
                        - height: 100px
                    tap_action:
                      action: toggle
                    type: custom:button-card

Below is a screenshot. See how “Lounge TV” button no longer has an icon… when pressed nothing happens either. This is because there is no ‘entity’ created regarding the switch
The “volume up/down” icons are also not colored either, which they should be ‘red’ and ‘blue’

The yaml for the switch is this:

      lounge_tv:
        command_on: curl -s http://x.x.x.x/api/xdevices.json?SetR=13
        command_off: curl -s http://x.x.x.x/api/xdevices.json?ClearR=13
        command_state: "curl -s http://x.x.x.x/api/xdevices.json?Get=R |grep R13 |cut -d : -f 2 | cut -b 2"
        value_template: '{{ value == "1" }}'

With a long list of similar type code for different devices all under the main ‘switch’ clause:

switch:
  - platform: command_line
    switches:
    ...

None of them are showing up anywhere in HA as ‘entities’??

I have had this configuration working for around 5 years without any real issues aside from a similar instance which I described above.

I am wondering if it really is because it’s an “unsupported system” and the base Python has either advanced too far ahead of HA or lagged a little behind causing this phenomenon?

HA itself runs in a docker container, so your base system is basically irrelevant, actually. You system is literally unsupported because your supervised installation is not supported, so any issue with, e.g. the Supervisor will leavr you without support.

But that is all irrelevant for your problem, in all likeliness.

Are you splitting your configuration, or is all your coding happening in configuration.yaml?

Sorry if I’m sounding a little like I don’t know what I’m doing… sadly it is anxiety and related to a few conditions…
There is too much going on in my head making it difficult to sort through and articulate coherently

With regards to Docker, yes I have had to use it plenty of times for trouble shooting and in some cases even repairing the install.
Again irrelevant to this but I’m even using iscsi for some mount points of the local file system from a main FreeBSD server (SAN system) as the actual install is run on VirtualBox.

Basically yes, all my config is happening inside the yaml configuration file. There are of course a few other files that I am making use of such as the automations.yaml file but again this was all part of the documentation when I originally set the thing up.

Looking at the configuration editor, it seems that I currently have around 3344 lines in there.

Should I break this up I wonder and instead say put the sensors and switches into their own respective files such as: switches.yaml and sensors.yaml?

Would that help?

Or is the problem elsewhere and what best course of action to try to narrow things down?

Right now I’m trying to break things up into their own files.

I created a file called switch.yaml and am calling it within configuration.yaml as such:

switch: !include switch.yaml

I’m a little confused now as to what is going on… somehow I think the syntax changed between versions as previously I have always used this to call the switches:

taken from the above posting eg.

switch:
  platform: command_line
  switches:
    switch name:

My switch.yaml file now has this inside it of which the syntax checker does not like:

- switch:  
    platform: command_line
      switches:
      garden_wall_lights:

However, the documentation is saying something different:

# Example configuration.yaml entry
command_line:
  - switch:
      name: Kitchen Light
      command_on: switch_command on kitchen
      command_off: switch_command off kitchen

In my switch.yaml I changed the config to:

- switch:  
      garden_wall_lights:

which seems ok… but then when I go into the developer tools “sates” section there is no switch called: garden_wall_lights ??

I am seeing this in the log file now so at least it is something:

Invalid config for 'switch' at switch.yaml, line 1: required key 'platform' not provided, please check the docs at https://www.home-assistant.io/integrations/switch

Ok… so I changed the file back to:

- switch:  
    platform: command_line
    switches:
      garden_wall_lights:

and got a Green Check for syntax!

Hmm… got this in the logs again:

Invalid config for 'switch' at switch.yaml, line 1: required key 'platform' not provided, please check the docs at https://www.home-assistant.io/integrations/switch

Really scratching my head now… this seems fine and doesn’t produce any “log” errors or output:

    platform: command_line
    switches:
      garden_wall_lights:

But no garden_wall_lights under “States”??

What is going on?

Might have a clue into things as this just showed up in the logs:

Logger: homeassistant.components.rest.data
Source: components/rest/data.py:114
integration: RESTful (documentation, issues)
Timeout while fetching data: http://x.x.x.x/api/xdevices.json?Get=R

Could it be that the full line hasn’t been executed?

It should be this:

      garden_wall_lights:
        command_on: curl -s http://x.x.x.x/api/xdevices.json?SetR=12
        command_off: curl -s http://x.x.x.x/api/xdevices.json?ClearR=12
        command_state: "curl -s http://x.x.x.x/api/xdevices.json?Get=R |grep R12 |cut -d : -f 2 | cut -b 2"
        value_template: '{{ value == "1" }}'

Now that you mention it, I remember having issues in the past with command_line and piping (“|”).

Try create a bash script and execute it instead, ie.

/config/shell/curl_state.sh

#!/bin/bash
curl -s http://x.x.x.x/api/xdevices.json?Get=R |grep R13 |cut -d : -f 2 | cut -b 2
        command_state: "bash /config/shell/curl_state.sh"

Hi Chris,

thanks a lot for helping out. I really appreciate it!

Last night I tried something similar to your suggestion.

I created a file in ‘/usr/bin/’ called “outdoor_temp” along the similar lines of what you put:

#!/bin/bash
curl -s http://x.x.x.x/api/xdevices.json?Get=XTHL | grep THL1-TEMP | cut -d : -f 2 | cut -d , -f 1 |  tr -d [:space:]

This would be for the outside temperature sensor.

Then calling in the “sensor.yaml” file as such:

  - platform: command_line
    command: "bash /usr/bin/outdoor_temp"
    unit_of_measurement: "°C"
    scan_interval: 60
    name: "Outside Temperature"

Guess what?

Nothing worked! It didn’t show up at all under “Entities”…

Today I moved the file under “/config/shell” as well as created a new one for the switch that you suggested.

 pwd
/usr/share/hassio/homeassistant/shell

$PATH is a bit different as ‘ssh’d’ into the base system and not the HA Docker instance… when transposed Docker will see this as:

/config/shell

Looking at the contents of the directory I now have these guys:

ls
garden_wall_lights  outdoor_temp

Neither are showing up??

I attempted to remove everything from the yaml files apart from just the points-of-interest, essentially either the sensor or the switch but that didn’t seem to work either.

Sadly I have lost heating and AC control in the house as I tied the whole thing into HA because of this issue…

Should I file a “bug report” or is there anything else I can try to get this working?

One that comes to mind is if I push things to the HA HTTP API via Cronjob, but that kind of defeats the purpose…

It would work with sensors but I don’t think it would work with the switches as pressing the buttons from the various control panels don’t do anything :frowning:

It’s very confusing.
Why that directory? It doesn’t exist nowhere on an HAOS installation, neither on the base OS, nor in the SSH addon nor in the HA container.

It seems you are using different tools while you don’t quite understand the architecture.
Use the Visual code addon to do your coding, that should lessen the confusion.

Tried something a little simpler as a test… I changed my temperature sensor to a static value:

  - platform: command_line
    command: echo "20"
    unit_of_measurement: "°C"
    scan_interval: 60
    name: "Outside Temperature"

Again… the sensor doesn’t show up as an Entity??

It should show as a constant value of “20” but it’s no where to be seen…

Maybe the “command_line” code is broken somewhere?

No no… I get the architecture (I think)

The docker instance is basically like a FreeBSD Jail or Solaris LDOM but doesn’t have a separate IP address…

It’s probably me confusing you here :slight_smile:

 docker exec -it homeassistant bash
 pwd
/config
cd shell
homeassistant:/config/shell# ls
garden_wall_lights  outdoor_temp

All is correct!

Ok, and what does bash /config/shell/outdoor_temp give you inside the container?

This:

cat outdoor_temp 
#!/bin/bash
#curl -s http://x.x.x.x/api/xdevices.json?Get=XTHL | grep THL1-TEMP | cut -d : -f 2 | cut -d , -f 1 |  tr -d [:space:]
echo "10"

Obviously “x.x.x.x” is the real IP address of the GCE IPX controller.

I initially tested with the “curl” command which did nothing, then I tried to use a simple “echo” instead for a constant value. This also did nothing?

If I run it from with the HA environment:

homeassistant:/config/shell# ./outdoor_temp 
10

Like I wrote above in my previous response I changed the command to try to output a static value of “20” using the “File Editor” addon and added “echo” directly as the command:

<url>:8123/core_configurator/ingress
  - platform: command_line
    command: echo "20"
    unit_of_measurement: "°C"
    scan_interval: 60
    name: "Outside Temperature

It should at least have something showing up but doesn’t.

Just checking more things that work and that don’t it seems like the “binary sensors” are working using the REST platform:

binary_sensor:
  - platform: rest
    resource: http://x.x.x.x/api/xdevices.json?Get=R
    value_template: '{{ value_json.R4 }}'
    name: "Buzzer"
  - platform: rest
    resource: http://x.x.x.x/api/xdevices.json?Get=R
    value_template: '{{ value_json.R5 }}'
    name: "Bell"
  - platform: rest
    resource: http://x.x.x.x/api/xdevices.json?Get=R
    value_template: '{{ value_json.R6 }}'
    name: "Bell External"

The guys are showing up under Entities which is good news!

From what I can see and maybe I’m wrong but there looks like an issue with the:

platform: command_line

Since neither switches nor sensors are functioning that make use of it.

Just changing this back in the file that you suggested to create it does run and work:

homeassistant:/config/shell# vi outdoor_temp 
homeassistant:/config/shell# ./outdoor_temp 
12.56homeassistant:/config/shell# cat outdoor_temp 
#!/bin/bash
curl -s http://x.x.x,x/api/xdevices.json?Get=XTHL | grep THL1-TEMP | cut -d : -f 2 | cut -d , -f 1 |  tr -d [:space:]
#echo "10"

You don’t happen to have multiple ‘sensor:‘ entries in your configuration.yaml, do you?

By that if you mean multiple definitions of “sensor” the answer is no…

but entries yes - this is how the sensor.yaml file looks:

  - platform: command_line
    command: echo "20"
    unit_of_measurement: "°C"
    scan_interval: 60
    name: "Outside Temperature"
  - platform: command_line
    command: "curl -s http://x.x.x.x/api/xdevices.json?Get=XTHL | grep THL1-LUM | cut -d : -f 2 | cut -d , -f 1 |  tr -d [:space:]"
    unit_of_measurement: "lux"
    scan_interval: 60
    name: "Outside Luminosity"    
  - platform: command_line
    command: "curl -s http://x.x.x.x/api/xdevices.json?Get=XTHL | grep THL1-HUM | cut -d : -f 2 | cut -d , -f 1 |  tr -d [:space:]"
    unit_of_measurement: "%"
    scan_interval: 60
    name: "Outside Humidity"    
  - platform: command_line
    command: "curl -s http://x.x.x.x/api/xdevices.json?Get=XTHL | grep THL2-LUM | cut -d : -f 2 | cut -d , -f 1 |  tr -d [:space:]"
    unit_of_measurement: "lux"
    scan_interval: 60
    name: "Kitchen Luminosity"    
  - platform: command_line
    command: "curl -s http://x.x.x.x/api/xdevices.json?Get=XTHL | grep THL2-HUM | cut -d : -f 2 | cut -d , -f 1 |  tr -d [:space:]"
    unit_of_measurement: "%"
    scan_interval: 60
    name: "Kitchen Humidity"    
  - platform: command_line
    command: "curl -s http://x.x.x.x/api/xdevices.json?Get=XTHL | grep THL3-LUM | cut -d : -f 2 | cut -d , -f 1 |  tr -d [:space:]"
    unit_of_measurement: "lux"
    scan_interval: 60
    name: "Living Room Luminosity"    
  - platform: command_line
    command: "curl -s http://x.x.x.x/api/xdevices.json?Get=XTHL | grep THL3-HUM | cut -d : -f 2 | cut -d , -f 1 |  tr -d [:space:]"
    unit_of_measurement: "%"
    scan_interval: 60
    name: "Living Room Humidity"  

It’s a similar thing with the switches - switch.yaml looks like this:

    platform: command_line
    switches:
      garden_wall_lights:
        command_on: curl -s http://x.x.x.x/api/xdevices.json?SetR=12
        command_off: curl -s http://x.x.x.x/api/xdevices.json?ClearR=12
        command_state: "bash /config/shell/garden_wall_lights"
        value_template: '{{ value == "1" }}'
      garden_main_lights:
        command_on: curl -s http://x.x.x.x/api/xdevices.json?SetR=11
        command_off: curl -s http://x.x.x.x/api/xdevices.json?ClearR=11
        command_state: "curl -s http://x.x.x.x/api/xdevices.json?Get=R |grep R11 |cut -d : -f 2 | cut -b 2"
        value_template: '{{ value == "1" }}' 
      porch_light:
        command_on: curl -s http://x.x.x.x/api/xdevices.json?SetR=10
        command_off: curl -s http://x.x.x.x/api/xdevices.json?ClearR=10
        command_state: "curl -s http://x.x.x.x/api/xdevices.json?Get=R |grep R10 |cut -d : -f 2 | cut -b 2"
        value_template: '{{ value == "1" }}'   

This is just a small snippet as there are quite a few entries like these…

switch.yaml is 632 lines long!

sensor.yaml is 1842 lines long!

Could you give a sample of what curl -s http://x.x.x.x/api/xdevices.json?Get=R returns

It outputs all the relay numbers and states within the IPX controller:

homeassistant:/config# curl -s http://x.x.x.x/api/xdevices.json?Get=R
{
    "product": "IPX800_V4",
    "status": "Success",
    "R1": 1,
    "R2": 0,
    "R3": 0,
    "R4": 0,
    "R5": 0,
    "R6": 0,
    "R7": 1,
    "R8": 1,
    "R9": 0,
    "R10": 0,
    "R11": 0,
    "R12": 0,
    "R13": 0,
    "R14": 0,
    "R15": 0,
    "R16": 0,
    "R17": 0,
    "R18": 0,
    "R19": 0,
    "R20": 0,
    "R21": 0,
    "R22": 1,
    "R23": 0,
    "R24": 0,
    "R25": 0,
    "R26": 0,
    "R27": 0,
    "R28": 0,
    "R29": 0,
    "R30": 0,
    "R31": 0,
    "R32": 0,
    "R33": 0,
    "R34": 0,
    "R35": 0,
    "R36": 0,
    "R37": 0,
    "R38": 0,
    "R39": 0,
    "R40": 0,
    "R41": 0,
    "R42": 0,
    "R43": 0,
    "R44": 0,
    "R45": 0,
    "R46": 0,
    "R47": 0,
    "R48": 0,
    "R49": 0,
    "R50": 0,
    "R51": 0,
    "R52": 0,
    "R53": 0,
    "R54": 0,
    "R55": 0,
    "R56": 0