Local Alexa and CMD Line Switches

I have two questions/problems:

  1. I’ve checked the Alexa component and am using the Emulated Hue Bridge. Since it is not able to control all feature of all devices (e.g. colors for lights) i’d like to use the better Alexa skill. In the tutorial I saw, that you need to setup dyndns so access HA from external. Our Internet provider does not provide ipv4 addresses anymore so I can’t access my HA from outside my network. Does that mean I am “stuck” with “Emulated Hue Bridge Alexa”?

  2. I’ve done a clean install of HA and used some of my pre-existing configurations. Somehow my command line switches won’t work properly anymore.
    Turning ON and OFF works. but none of them show the state when the devices are turned on.
    I can see the commands being executed in the log. But the state does not change.

this is my config:
`switch:

  • platform: command_line
    switches:
    playstation4:
    command_on: ‘ps4-waker’
    command_off: ‘ps4-waker standby’
    command_state: ‘ps4-waker search | grep -i “200 Ok” > nul && (echo “true”) || (echo “false”)’
    value_template: ‘{{ value }}’
    friendly_name: “Playstation”
    netflix:
    command_on: ‘ps4-waker start CUSA00127’
    command_off: ‘ps4-waker remote ps’
    command_state: ‘ps4-waker search | grep -i “CUSA00127” > nul && (echo “true”) || (echo “false”)’
    value_template: ‘{{ value }}’
    friendly_name: “Netflix”
    tv:
    command_on: ‘echo on 0 | cec-client -s -d 1’
    command_off: ‘echo standby 0 | cec-client -s -d 1’
    command_state: ‘echo pow 0 | cec-client -s -d 1 | grep -i “power status: on” > nul && (echo “true”) || (echo “false”)’
    value_template: ‘{{ value }}’
    friendly_name: “TV”`

Does anyone have an idea?

Is there maybe a way I can make HA print the result of the command_state?
I can see it being called but the state does not change accordingly.
This way I could see what happens when the command_state is called and what the result is to narrow down where the problem is.

Hi @HansWurst90, you can run the command in a terminal to see the output.
Don’t forget to activate the virtualenv if HA lives there.

I’m using the Hassbian image and when I’m running the command in the terminal as the user homeassistant user it turns the devices on and off and returns true/false as it should.
When I use Homeassistant, the on/off commands work, but the state does not.
Is the commands working in the terminal as homeassistant user a valid ‘comparison’ to when Home assistant calls it?

What exactly is the virtualenv and how do I activate it?

As HA user type:
source /srv/homeassistant/bin/activate
after this you should see
(homeassistant)
in front of your prompt.

Virtualenv -> https://home-assistant.io/docs/installation/virtualenv/

Alirght, I will have a look into that tonight and see if I can find the cause of my issue
Thank you!

@VDRainer

homeassistant@hassbian:~ $ source /srv/homeassistant/bin/activate
(homeassistant) homeassistant@hassbian:~ $ echo pow 0 | cec-client -s -d 1 | grep -i “power status: on” > nul && (echo “true”) || (echo “false”)
false
(homeassistant) homeassistant@hassbian:~ $ ps4-waker search | grep -i “200 Ok” > nul && (echo “true”) || (echo “false”)
false
(homeassistant) homeassistant@hassbian:~ $ ps4-waker search | grep -i “CUSA00127” > nul && (echo “true”) || (echo “false”)
false

If understand correctly, this shows, that my commands are correct, right?
these commands + value_template: '{{ value }}' should make HA get the correct state.

I dont have ps4-waker or cec-client, but if your switches are on, the commands must return true to show the right state of the switch.

Test your commands like this when the switches are on:
echo pow 0 | cec-client -s -d 1 | grep -i "power status: on"
it should print a line with “power status: on” in it.

ps4-waker search | grep -i "200 Ok"
it should print a line with “200 Ok” in it.

ps4-waker search | grep -i "CUSA00127"
it should print a line with “CUSA00127” in it.

A simple example how this works:

server:~$ echo hello hanswurst | grep -i wurst
hello hanswurst
server:~$ echo hello hanswurst | grep -i wurst > nul && (echo "true") || (echo "false")
true
server:~$ echo hello hanswurst | grep -i fisch
server:~$ echo hello hanswurst | grep -i fisch > nul && (echo "true") || (echo "false")
false
server:~$

The ‘{{ value }}’ is not needed IMO.

Sorry, I didn’t explain myself correct. At the time when I tested it, the “false” results were the correct response.
I just tested it again with the devices turned on and the commands return true. So the issue must be some where after the commands were called.
I gonna try the value, although the documentation says either value_template must be true/false or the command itself must return 0 or something else.

Sorry, i was wrong, you need the template.
Testet a switch with only:

command_state: "echo false"
value_template: '{{ value }}'

and

command_state: "echo true"
value_template: '{{ value }}'

Like expected, true -> switch on, false -> switch off
It takes e few seconds to show the right state.

I’m basically still clueless.
My turn on/off commands work.
My state commands are right (in the env they return true and false as they should) but HA does not change the state…
Is there a way to see what HA gets as a response from the command? Somewhere between calling the command and updating the UI must be the problem.