Addon State Check: Command Line Binary Sensor

Hi community, can anyone see where I’m going wrong? Hass.io installed on a RP3 here, trying to make a sensor to detect the current state of one of my addons and express it as a binary sensor. (Primarily to run HerrHofrat’s motion addon with a USB webcam, but to turn it on / off via a switch I can run automations against for when I get home / leave for work)

binary_sensor:
  - platform: command_line
    command: '/usr/bin/hassio addons info 657d34cb_motion --raw-json'
    name: Addon State
    value_template: "{{value_json['data']['state']}}"
    payload_on: 'started'
    payload_off: 'stopped'

Problem is I get this back:

Command failed: /usr/bin/hassio addons info core_duckdns --raw-json

Did you ever solve this :)?

I did! Although I wouldn’t say it’s the cleanest method but I used a REST sensor, replacing the bits in square brackets:

sensor:
  - platform: rest
    resource: "https://[home assistant web address]/api/hassio/addons/[addon name (from the address bar when you go to configure it in hass.io)]/info"
    headers:
      Authorization: "Bearer [user generated Long-Lived Access Token]"
      Content-Type: application/json
    name: [choose a name for this REST sensor]
    value_template: "{{value_json['data']['state']}}"

You can then also make a switch for it (which is useful for the interface / automations):

switch:
  - platform: template
    switches:
      [pick a switch name use underscores]:
        value_template: "{{ is_state('sensor.[REST sensor name]', 'started') }}"
        turn_on:
          service: hassio.addon_start
          data:
            addon: "[addon name]"
        turn_off:
          service: hassio.addon_stop
          data:
            addon: "[addon name]"
1 Like

@dangrin0

https://community.home-assistant.io/t/service-hassio-addon-not-working/183130

Can you help me with this? I see you experimented with service hassio.addon_stop/start?

Whi not working? What must be enabled to this service to work.

Here is my addon config.json:

{
  "name": "KODI 18.6 with SMB",
  "version": "dev-0.6.0a",
  "slug": "kodi_18_smb",
  "description": "KODI 18.6 media center with samba store add-on!",
  "arch": ["armhf", "armv7"],
  "startup": "application",
  "boot": "manual",
  "ports": {
    "8080/tcp": 8080
  },
  "host_dbus":"yes",
  "devices": [
    "/dev/fb0:/dev/fb0:rwm",
    "/dev/vchiq:/dev/vchiq:rwm",
    "/dev/input:/dev/input:rwm",
    "/dev/tty:/dev/tty:rwm",
    "/dev/snd:/dev/snd:rwm",
    "/dev/bus:/dev/bus:rwm",
    "/dev/vcio:/dev/vcio:rwm",
    "/dev/vcsm:/dev/vcsm:rwm",
    "/dev/vc-mem:/dev/vc-mem:rwm"
  ],
  "webui": "http://[HOST]:[PORT:8080]/",
  "privileged": ["SYS_ADMIN","DAC_READ_SEARCH"],
  "full_access": "true",
  "map": ["share:rw","ssl:rw"],
  "options": {
    "kodi_data": "kodi",
    "smb_ip": "192.168.0.198",
    "smb_path": "smb$/data",
    "smb_user": "smbuser",
    "smb_pass": "smbpass"
  },
  "schema": {
    "kodi_data": "str",
    "smb_ip": "str",
    "smb_path": "str",
    "smb_user": "str",
    "smb_pass": "password"
  }
}