Automation on a template sensor does not trigger

Hello,
I have a 2 file sensors each linked to a file containing the Tx and Rx of the Ethernet card of a Linux Server.(updated every minute) and a template sensor to total the two to use as a trigger level in (lower than) in an automation

#activity on ethernet interface Z420-2
- platform: file
  name: Z420-2-L-rx
  file_path: /config/file_sensors/pete-Z420-2-L_eno1_rx
  unit_of_measurement: "Bytes/sec"

- platform: file
  name: Z420-2-L-tx
  file_path: /config/file_sensors/pete-Z420-2-L_eno1_tx
  unit_of_measurement: "Bytes/sec"
  
- platform: template
  sensors:
    total_z420_2_l_rx_tx:
      unit_of_measurement: "Bytes/sec"
      value_template: "{{ states('sensor.z420_2_l_rx') | float + states('sensor.z420_2_l_tx') | float }}"

The sensors work fine.

I want to switch off the server when it is not streaming anything for 30 minutes:

alias: "Bureau: Z420 Off when Rx+Tx < 50k/s for 30 mins"
description: "Bureau: Z420 Off when Rx+Tx < 50k/s for 30 mins"
trigger:
  - platform: numeric_state
    entity_id: sensor.total_z420_2_l_rx_tx
    for:
      hours: 0
      minutes: 1   #for test only
      seconds: 0
    below: 50000
condition:
# for test only: the conditon tests True
  - condition: numeric_state
    entity_id: sensor.total_z420_2_l_rx_tx
    below: 50000
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.pete_z420_2_l
mode: single

The Automation does not trigger
and I cannot figure out why not.

Thanks in advance for any help or suggestion.

What is your testing method? In order for a Numeric state trigger to fire the value must change from above threshold to below the threshold. It will not fire if the threshold is already passed when the automation is reloaded.

That (beginner’s error) is likely to be the issue!
Thank you!

Back to the drawing board!

wouldn’t it be easier to set up snmp service on the linux server?

Just in case it interests some-one: The following works:
I created a timer helper and an automation which is triggered by the start of the PC or the passing (low to high) of the Ethernet activity limit. In the action of the automation, a loop will reset the timer every minute while the Ethernet activity remains above the limit.

alias: "Bureau: Z420-2 Manage Threshold Timer"
description: "Bureau: Z420-2 Manage Threshold Timer"
trigger:
  - platform: numeric_state
    entity_id: sensor.total_z420_2_l_rx_tx
    above: 50000
  - platform: state
    entity_id:
      - switch.pete_z420_2_l
    from: "off"
    to: "on"
condition: null
action:
  - service: timer.start
    data:
      duration: "1800"
    target:
      entity_id: timer.z420_2_thresholdtimer
  - repeat:
      while:
        - condition: numeric_state
          entity_id: sensor.total_z420_2_l_rx_tx
          above: 50000
      sequence:
        - delay:
            hours: 0
            minutes: 0
            seconds: 60
            milliseconds: 0
        - service: timer.start
          data:
            duration: "1800"
          target:
            entity_id: timer.z420_2_thresholdtimer
mode: single

When the timer reaches zero another automation switches of the machine.

alias: "Bureau: Z420-2 Off when Threshold timer = 0"
description: "Bureau: Z420-2 Off when Threshold timer = 0"
trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.z420_2_thresholdtimer
    context: {}
condition: []
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.pete_z420_2_l
mode: single

The timer helper can be shown on the HA display to show progress

At first glance, I would not think so. (Although it took me a while to get the script which retrieves absolute Rx and Tx values from /proc/net/dev and convert that in rates/sec to put on HA)
I now have all info together (of course I only really need the on/off switch :slight_smile: )