kvj / hass_openwrt

Home Assistant integration with OpenWrt devices
MIT License
114 stars 20 forks source link

How to Create Sensors #9

Open lmath56 opened 2 years ago

lmath56 commented 2 years ago

Hi,

I am having some trouble creating Sensors. I have followed the steps and I can see the below: image

I would like to create sensors for different things such as system uptime, how many dhcp leases, public ip address, etc. I've done a bit of research but haven't had much luck.

I was able to use the openwrt.reboot service to restart OpenWRT. Can I possibly parse the output from openwrt.exec command to a sensor?

Thanks!

kaciker commented 1 year ago

Same question

Asiak3 commented 1 year ago

same

kvj commented 1 year ago

Hey,

Can I possibly parse the output from openwrt.exec command to a sensor?

In theory - yes. But it's not implemented. The standard output is available as part of the Ubus call response, but it should be somehow exposed to 3rd-party scripts or automatons.

The easy way - emit Hass event after each openwrt.exec call with the output and exit code, but you will need to listen to that event using Hass automation, parse the output and update one of your helper sensors for that.

Another approach - add and update custom OpenWrt sensor with output of openwrt.exec response. With this approach, you can create template sensors and parse output. A bit easier to support your custom code (one template sensors vs. helper + automation), but more difficult to support multiple commands

blackie333 commented 1 year ago

Considering this integration for monitoring 2 openlumi devices (openwrt in client-wifi mode) with some sensors (lamp, button switch, luminance sensor) and Zigbee router integrated. Sometimes (after HA restart) related HA entities got stuck with no values and I have to reboot both openlumi devices. I would like to use the reboot service in automation but also would like to use an uptime sensor.

Would it be possible to explain in more details how to create an uptime sensor in HA (via template sensor in config.yaml), based on the default openwrt configuration? Thanks in advance

kvj commented 1 year ago

Would it be possible to explain in more details how to create an uptime sensor in HA (via template sensor in config.yaml)

There's no way, currently. You can exec any program using the service the integration provides, but its standard output isn't available. That should be implemented first

bkbartk commented 1 year ago

I would like to know also, but when I try

service: openwrt.exec
data:
  command: system board
target:
  device_id: b8c531xxxxxxx84291020

or some variation, I only get permission errors. openwrt.reboot works I think I messed up some permissions, or I don't know what to fill for command.

edit: sorry, missed this part

There's no way, currently. You can exec any program using the service the integration provides, but its standard output isn't available. That should be implemented first

still I have some permissions issues, but when I can't get the result, it won't matter