Ok sorry, long reply here. I played around a bit to see if I could make sense of everything.
Great idea, thanks a lot, turning off the kodi definitely works like this! I have also tried to make scripts that can turn on/off TV via kodi’s CEC (since I also use it for music, and don’t wat the TV on for that). What I tried to use was:
#!/bin/bash
sshpass -p 'libreelec' ssh [email protected] "echo 'on 0' | cec-client -s"
Which, again, worked when I ran as user pi, but not when running as homeassistant. Staying in your line of thought, I found on github, that:
http://localhost:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Addons.ExecuteAddon","params":{"addonid":"script.json-cec","params":{"command":"activate"}},"id":1}
should turn on a TV connected to kodi through CEC, (I wasn’t sure about the syntax) so I tried using either:
- platform: command_line
switches:
tv_test:
command_off: curl -i -X POST -H "Content-Type: application/json" -d ‘{“jsonrpc":"2.0","method":"Addons.ExecuteAddon","params":{"addonid":"script.json-cec","params":{"command":"standby"}},"id”:1}’ http://USER:[email protected]:8080/jsonrpc
command_on: curl -i -X POST -H "Content-Type: application/json" -d ‘{“jsonrpc":"2.0","method":"Addons.ExecuteAddon","params":{"addonid":"script.json-cec","params":{"command":"activate"}},"id”:1}’ http://USER:[email protected]:8080/jsonrpc
```
or
```
- platform: command_line
switches:
tv_test:
command_on: curl -i -X POST -H "Content-Type: application/json" -d http://USER:[email protected]:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Addons.ExecuteAddon","params":{"addonid":"script.json-cec","params":{"command":"activate"}},"id":0}
command_off: curl -i -X POST -H "Content-Type: application/json" -d http://USER:[email protected]:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Addons.ExecuteAddon","params":{"addonid":"script.json-cec","params":{"command":"standby"}},"id":0}
```
I tried from the terminal, but I get errors. The first one just returns:
```
HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Type: application/json
Content-Length: 76
Cache-Control: private, max-age=0, no-cache
Accept-Ranges: none
Date: Wed, 05 Apr 2017 21:55:49 GMT
{"error":{"code":-32700,"message":"Parse error."},"id":null,"jsonrpc":"2.0"}
```
without doing anything (turning on the TV), the second one returns the same, but followed by three times:
```
{"error":{"code":-32700,"message":"Parse error."},"id":null,"jsonrpc":"2.0"}HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Type: application/json
Content-Length: 76
Cache-Control: private, max-age=0, no-cache
Accept-Ranges: none
Date: Wed, 05 Apr 2017 21:39:21 GMT
```
Just for the heck of it, I tested your exact code (in terminal), and that gives the same error (as the first). Running in homeassistant gives the following in the log (where the position in question is the colon in `"Content-Type: application/json"`):
```
17-04-05 22:28:59 ERROR (Thread-1) [homeassistant.util.yaml] mapping values are not allowed here
in "/home/homeassistant/.homeassistant/switches.yaml", line 45, column 53
17-04-05 22:28:59 ERROR (MainThread) [homeassistant.bootstrap] Error loading /home/homeassistant/.homeassistant/configuration.yaml: mapping values are not allowed here
in "/home/homeassistant/.homeassistant/switches.yaml", line 45, column 53
```
@cgtobi
I know, it's not optimal, but this was the solution I could think of. As mentioned, I can't setup the keys for ssh on the libreelec (that I use for ssh to other systems). I thought that since the libreELEC is such a blunted system, and I hopefully secured my home assistant well enough (using two-factor authentication for ssh login to that, and using let's encrypt ssl certificates for remote access), I could live with this.
@PhyberApex
I looked a bit into which one to chose a while back, and it seemed that a lot of the top developers for openELEC left to start libreELEC, and it also seemed that libreELEC was more up to date (i.e. currently being developed when I installed). I tried OSMC, but I hadn't heard of RaspBMC, I might give that a go.
I don't have any Allow/Deny Groups/Users in the `/etc/ssh/sshd_config`, does that default to "everyone has access"? Or should I specifically set up `AllowUsers pi homeassistant`, or something like that?