Error with running command line

I’m trying to monitor the bandwidth of my WAN connection on my MikroTik router. I’ve tried it with the snmp sensor but that wouldn’t work so I figured the easiest way was to run a command line command to retrieve the value.

I’ve installed snmpget on my home assistant running a hassio intallation on a RPi3. When running the command via the SSH & Web Terminal add-on i get the results I want. Once i put it in my configuration.yaml it doesn’t work.

I cant find a solution, someone got a tip for me?

config:

# Mikrotik bandwidth monitor
  - platform: command_line
    name: WAN-in
    command: "snmpget -v 2c -c public -Oqv 192.168.1.1 1.3.6.1.2.1.31.1.1.1.6.1"

  - platform: command_line
    name: WAN-out
    command: "snmpget -v 2c -c public -Oqv 192.168.1.1 1.3.6.1.2.1.31.1.1.1.10.1"

error log:

2020-02-08 14:04:26 ERROR (SyncWorker_16) [homeassistant.components.command_line.sensor] Command failed: snmpget -v 2c -c public -Oqv 192.168.1.1 1.3.6.1.2.1.31.1.1.1.6.1
2020-02-08 14:04:27 ERROR (SyncWorker_19) [homeassistant.components.command_line.sensor] Command failed: snmpget -v 2c -c public -Oqv 192.168.1.1 1.3.6.1.2.1.31.1.1.1.10.1

I also have Hassio installed on rPi3.
When I type snmpget into the terminal the response is command not found

That is correct, you have to install it first. The Hassio image is running Alpine Linux, with the command below you’ll get snmpget.

apk add net-snmp-tools

1 Like

I don’t use hassio (or what is now just called Home Assistant, as opposed to Home Assistant Core), but I’ve seen people have this issue over and over again. I’m led to understand that it might be a permission or access issue. One thing that might be coming into play is that HA is run in a separate docker container (not sure if I’m using the terms correctly) than the ssh add-on, so running a command successfully in one context doesn’t always apply to the other. Honestly, I’m not sure what the solution is, but if you search this forum I’m sure you’ll eventually run into several (hundred) topics that contain a useful answer.

This thread might help. We ssh out of the container and issue the commands on the host.