Is it possible to make a SNMP request on the hour (every hour)?

Hello,

I’m hoping that someone can point me in the right direction on this please. I would like get my internet traffic usage every hour, on the hour (ie at 00:00, 01:00, 02:00, etc). Currently I’m polling my router at an interval of an hour, but not on the hour.

- platform: snmp
    name: 'test interval WAN out'
    host: 192.168.1.1
    baseoid: .1.3.6.1.2.1.31.1.1.1.10.1
    community: 'public'
    version: '2c'
    scan_interval: 3600

I found this speedtest-changed-setup-how-to-scan-at-0-6-12-18-hours. But unfortunately that method did not work with SNMP. Is there another way that I could poll on the hour?

Thanks

You could run snmp as a command line and kick it off via an hourly service/automation

Are you sure you can keep it at one hour?
A 1gbit/s connection at full speed will make a second overflow in the counter in about 34 seconds.
You probably don’t have a 1gbit/s internet connection, but one hour means overflow can be reached at with less than a 1000/90=11mbit/s at full speed.

An overflow is when the counter reach the highest number it can hold and then starts at 0 again.
The second overflow is the important one, because when you reach that time point without readings in between you will not know if you have a high number from running at full speed and two overflows or just half the speed with one overflow.

Thanks, that sounds like a good idea. I’ll give it a go tomorrow.

Good point about the overflow, but luckily they are 64 bit counters.

Thanks @vingerha , it seems to be working.

I’ve briefly documented what I did in case it helps other HA beginners. (no guarantees its right though !)

configuration.yaml

  - platform: command_line
    name: 'usg_wan_in'
    command: "snmpget -Oqv -v 2c -c public 192.168.1.1 .1.3.6.1.2.1.31.1.1.1.6.1"
    scan_interval: 10000000
  - platform: command_line
    name: 'usg_wan_out'
    command: "snmpget -Oqv -v 2c -c public 192.168.1.1 .1.3.6.1.2.1.31.1.1.1.10.1"
    scan_interval: 10000000

(the OIDs are for port 1 in my Mikrotik router, and might be N/A for your setup)

automations.yaml

- id: GetWanCounter
  alias: "SNMP poll hourly"
  trigger:
    - platform: time_pattern
      minutes: "00"
  action:
    - service: homeassistant.update_entity
      target:
        entity_id:
        - sensor.usg_wan_in
        - sensor.usg_wan_out

docker container terminal (I’m using HA in a Docker container)

apk update
apk add net-snmp
apk add net-snmp-tools
snmpget -Oqv -v 2c -c public 192.168.1.1 .1.3.6.1.2.1.31.1.1.1.10.1```