SNMP based command line switch

I have an APC PDU in my garage - where I keep my Home Lab setup. Plugged in to socket 1 is the garage light.

I can run the following commands as the homeassistant user and they work

Turn on the light
/usr/bin/snmpset -v 1 -c private integer 1

Turn off the light
/usr/bin/snmpset -v 1 -c private integer 2

Get the status - returns 1 or 2
/usr/bin/snmpget -Oqv -v 1 -c public

So I put this in as a switch configuration.

   - platform: command_line
      command_on: "/usr/bin/snmpset -v 1 -c private integer 1"
      command_off: "/usr/bin/snmpset -v 1 -c private integer 2"
      command_state: "/usr/bin/snmpget -Oqv -v 1 -c public"
      value_template: '{{ return_value == "1" }}'
      friendly_name: Garage Light

The switch appears in the HA interface but it doesn’t work. If I click the switch it slides over but then slides back after a few seconds. Also, if I turn the light on from the command line the switch in the interface still appears off.

This would imply that none of these commands are working.

I’ve found loads of examples where people’s command_on|off|status are curl commands but none using SNMP.

Can anyone see what I’m missing?




Fixed it. Although the example says

value_template: '{{ return_value == "1" }}'

It works if I change it to

value_template: '{{ value == "1" }}'