hass-opnsense icon indicating copy to clipboard operation
hass-opnsense copied to clipboard

Allow interface traffic to be used in statistics

Open Happyrobot33 opened this issue 1 year ago • 12 comments

Was lacking the utility sensors I had from when I was using a off the shelf router and integration, so I decided to add them :) I also fixed the fact that the display name of the interface sensors doesn't clean up the _ making them not look good if you directly add them to lovelace without overwriting the display name on a card

closes #84

Happyrobot33 avatar May 06 '23 04:05 Happyrobot33

Needs fixing, the meters don't seem to reset for some reason. I'm likely reading the documentation wrong

Happyrobot33 avatar May 07 '23 15:05 Happyrobot33

implemented a possible fix, give me a day to see if it works

Happyrobot33 avatar May 07 '23 15:05 Happyrobot33

So I just realized I'm doing this wrong because last_reset is only happening on the sensor creation, not in update. But even reloading the integration doesn't seem to make the value drop to 0, so I really don't know what's wrong

Happyrobot33 avatar May 08 '23 04:05 Happyrobot33

yeah this is more of a pain than I thought it would be, there doesnt seem to be anything a integration can hook into that just does this for them, so itd have to be coded manually to do the difference.....

Happyrobot33 avatar May 08 '23 12:05 Happyrobot33

gonna try to see if I can do it through opnsense's api instead of emulating it in HA

Happyrobot33 avatar May 08 '23 12:05 Happyrobot33

ok so TLDR, im stupid and didnt realize how home assistant statistic sensors worked. all that needed to be changed is for the state_class of some entitys to be total_increasing so home assistant knows how to store them

Happyrobot33 avatar May 08 '23 13:05 Happyrobot33

Thanks! I know it’s a pain but the _ business has been discussed ad-nauseam and I’d prefer not mess with that right now :(

The metrics look great! I think we may need to tighten the logic a little bit to ensure it only includes that attribute/value on appropriate sensors. Some of those sensors in that loop may be packets/bytes per second which would not correlate properly to the total increasing property.

travisghansen avatar May 08 '23 13:05 travisghansen

For cumulative sensors:

  • device_class: SensorDeviceClass.DATA_RATE
  • state_class: total_increasing

For instant measurement sensors:

  • device_class: SensorDeviceClass.DATA_RATE
  • state_class: measurement

(reference: https://developers.home-assistant.io/docs/core/entity/sensor)

alexdelprete avatar May 08 '23 13:05 alexdelprete

Thanks! I know it’s a pain but the _ business has been discussed ad-nauseam and I’d prefer not mess with that right now :(

The metrics look great! I think we may need to tighten the logic a little bit to ensure it only includes that attribute/value on appropriate sensors. Some of those sensors in that loop may be packets/bytes per second which would not correlate properly to the total increasing property.

Possibly make the _ configurable then?

The per second ones are already covered due to the order of the if statements, unless im missing something

Happyrobot33 avatar May 08 '23 14:05 Happyrobot33

Keeping configuration values at a minimum.

Indeed you are right we should be good for the per second stuff. I'll merge when I get a moment and snap a new release!

travisghansen avatar May 08 '23 14:05 travisghansen

Keeping configuration values at a minimum.

Indeed you are right we should be good for the per second stuff. I'll merge when I get a moment and snap a new release!

well hold on ill have to remove the _ change correct?

Happyrobot33 avatar May 08 '23 14:05 Happyrobot33

ive removed the _ change so it should be good to merge @travisghansen

Happyrobot33 avatar May 10 '23 15:05 Happyrobot33

Thanks for the contribution! This is already available in current releases so closing.

travisghansen avatar Mar 18 '24 17:03 travisghansen