Webhook: curl and cron

Preview Webhook: curl and cron

a simple cron job (Scheduled Tasks) on an Openwrt access point, everything that the Linux terminal makes available can be transmitted to Home-Assistant. As an example, my OpenWrt devices provide the following information:

  • The list of all connected clients.
  • CPU and memory utilization.
  • The last entry in the kernel log.
  • The DHCP leases from the main router.
  • Usteer data from the main router for the network overview.

The cron job starts every minute and enables continuous monitoring and management of the network infrastructure via Home Assistant.

Basics for this implementation, see: Display datafrom any Linux systems in HA!]

Prerequisite on the access points: curl

To enable the access points to send data to a webhook in Home Assistant, only the small software package "curl" is required:

Once curl has been installed, any commands can be transmitted to Home Assistant every minute, for example via Scheduled Tasks:

Scheduled Tasks

I use the following commands in the Scheduled Tasks on the access points to collect the data. The commands can be adapted as required or extended with additional commands. It makes sense to test the commands in a terminal beforehand.

* * * * * log=$(dmesg 
	
<p>I have created the following sensors for reception:</p>
<p>For the main router:</p>
<ul>
<li>input_text.openwrt_log (last log line of the kernel log, standard helper sensor)</li>
<li>sensor.openwrt_load (CPU utilization, Variables+History Sensor)</li>
<li>sensor.openwrt_ram (RAM utilization, Variables+History Sensor)</li>
<li>sensor.openwrt_crondata (DHCP and Usteer data, Variables+History Sensor)</li>
</ul>
<p>and for the access points:</p>
<ul>
<li>input_text.APNAME_log (Standard Helper Sensor)</li>
<li>sensor.APNAME_load (Variables+History Sensor)</li>
<li>sensor.APNAME_ram (Variables+History Sensor)</li>
</ul>
<p>The automation for filling the sensors looks as follows:</p>
<div class="scroll-container"><a class="disable-scroll" title="expand">[+]</a>
<div class="scroll-content">
<pre class="language-yaml"><code>alias: WebHook-OpenWrt
description: ""
triggers:
  - trigger: webhook
    allowed_methods:
      - POST
      - PUT
    local_only: true
    webhook_id: "???-OpenWrt"
conditions: []
actions:
  - action: input_text.set_value
    metadata: {}
    data:
      value: "{{ trigger.data.log }}"
    target:
      entity_id:
        - input_text.openwrt_log
  - action: variable.update_sensor
    metadata: {}
    data:
      replace_attributes: true
      attributes:
        dhcp: "{{ trigger.data.dhcp }}"
        usteer: "{{ trigger.data.usteer }}"
        stations: "{{ trigger.data.stations }}"
      value: >-
        {% set Stations = trigger.data.stations.split('Station ') %} {% for
        Station in Stations if (Station.split("\n")[0].split(" (")[0] != "")%}
        {% set StationDetail = Station.split("\n") %}{% set mac =
        StationDetail[0].split(" (")[0] %}{{ mac.replace(":","") }}{% endfor %}
    target:
      entity_id: sensor.openwrt_crondata
  - action: variable.update_sensor
    metadata: {}
    data:
      replace_attributes: false
      value: "{{ trigger.data.uptime.split(\": \")[1].split(\",\")[0]  }}"
    target:
      entity_id: sensor.openwrt_load
  - action: variable.update_sensor
    metadata: {}
    data:
      replace_attributes: false
      value: "{{100 - trigger.data.free | float}}"
    target:
      entity_id: sensor.openwrt_ram
mode: parallel
max: 10

The automation of the access points is the same, with the exception of the DHCP and Usteer data.

Dashboard

I then created the following markdown card for each of the access points:

[+]
{% set dhcplist = states.sensor.openwrt_crondata.attributes.dhcp.split('\n') %}
{% set Stations = states.sensor.openwrt_crondata.attributes.stations.split('Station ') %}
{% set DetailsColumns = (1,9,11,13)%}
{% if (Stations | count > 1) %}
{%set fontcolor="999"%}
{% for Station in Stations if (Station.split("\n")[0].split(" (")[0] != "")%}
{% set StationDetail = Station.split("\n") %}
{% set mac = StationDetail[0].split(" (")[0] %}
{% set dev = StationDetail[0].split(" (")[1].replace("on phy1-ap1)","2,4G").replace("on phy1-ap0)","2,4G").replace("on phy0-ap0)","5G").replace("on phy0-ap1)","5G") %}
{% set match = dhcplist | select('match', mac) | list%}
 {%if match %} 
  {% set match = match[0].split("_") %}
  {% if(StationDetail[1].split(":")[1].replace("ms","") | int > 1000) %}{%set fontcolor="999"%}{% else%}{%set fontcolor="fff"%}{% endif%}

 {% else %}
 
 {% endif %}

{% endfor %}
Lease Device Wifi Details
{{(now().timestamp() | int - (match[2] | int) + 43200 ) | timestamp_custom('%H:%M',false) }} {{match[1]}}
{{mac}}
- {{mac }} {{dev}} {% for DetailsColumn in DetailsColumns %} {{StationDetail[DetailsColumn].split(":")[0]}}:{{StationDetail[DetailsColumn].split(":")[1]}}
{% endfor %}

{% else %}
keine Verbindungen ..
{% endif %}

The sensor name, in this case "sensor.openwrt_crondata", must of course be created in advance for each access point and adjusted here.

The counters for CPU and RAM can also be used for the charts:

Conclusion

The use of webhooks in conjunction with curl and cron enables effective monitoring of Linux-based network systems in Home Assistant. By regularly transferring network data such as CPU and RAM utilization, connected clients and DHCP leases, the network infrastructure always remains up-to-date. The implementation is simple and only requires the installation of curl on the access points.

 

positive Bewertung({{pro_count}})
Rate Post:
{{percentage}} % positive
negative Bewertung({{con_count}})

THANK YOU for your review!

created by Bernhard | published: 2025-08-07 | Updated: 2025-08-07 | Übersetzung Deutsch |🔔 | Comments:0

Questions / Comments


 
By continuing to browse the site, you agree to our use of cookies. More Details