Notification Question

Is there a way to add into the notification how long the amps were above 2?


alias: The Pump Turned On
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.outdoor_smart_plug_with_power_meter_electric_consumption_a
    above: 2
conditions: []
actions:
  - action: notify.mobile_app_paddy_iphone
    metadata: {}
    data:
      message: The Pump Turned On
  - action: notify.persistent_notification
    metadata: {}
    data:
      message: The pump turned on
mode: single

The way you have the automation set up it should send the notification instantly when the state goes above 2.

so the notification will always say that the amps were above 2 for a few seconds ago or less.

I’d like to know how long the pump stays on. Anyway to do that?

Trigger with a trigger_id when it goes on. the action is to store that time in a helper.
Trigger with another trigger_id when it goes off, Action collect the time then subtract the time from the helper, and notify that result.
Use a choose statement to run the 2 actions based on the trigger_id.

you can create a sensor using the pumps “on” state but it gets a bit complicated.

you can create a trigger template sensor that sets a timestamp when the pump turns on and then another for when the pump turns off. then just create the sensor as the time difference between the two.

but you have to set it up so that it only tells you the on time so only calculate the time difference if the off time is after the on time.

here is an example of collecting the two times for my heat cycle time:

- automation:
  - alias: HVAC Main Heat Cycle Set Timestamps
    id: hvac_main_heat_cycle_set_timestamps
    triggers:
      - trigger: state
        entity_id: binary_sensor.main_heat_active
        to: 
          - 'on'
          - 'off'
        from: 
          - 'on'
          - 'off'
    actions:
      - if:
          - condition: template
            value_template: "{{ trigger.to_state.state == 'on' }}"
        then:
          - action: input_datetime.set_datetime
            target:
              entity_id: input_datetime.hvac_heat_active_start_time
            data:
              timestamp: "{{ now().timestamp() }}" 
        else:
          - action: input_datetime.set_datetime
            target:
              entity_id: input_datetime.hvac_heat_active_stop_time
            data:
              timestamp: "{{ now().timestamp() }}"

then I use the two times in the sensor portion to calculate the on time:

- template:
    - sensor:
        - name: Main Heat Run Cycle Duration
          state: >
            {% if (state_attr('input_datetime.hvac_heat_active_stop_time', 'timestamp') | float > state_attr('input_datetime.hvac_heat_active_start_time', 'timestamp') | float) %}
              {{ (state_attr('input_datetime.hvac_heat_active_stop_time', 'timestamp') | float - state_attr('input_datetime.hvac_heat_active_start_time', 'timestamp') | float) / 60 }}
            {% else %}
              {{ states('sensor.main_heat_run_cycle_duration') }}
            {% endif %}
          unit_of_measurement: min
          unique_id: main_heat_run_cycle_duration

you can combine the two but I don’t.

Is there anyway to set the date and time that it turned on in the notification? I can’t figure out how


alias: The Pump Turned On
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.outdoor_smart_plug_with_power_meter_electric_consumption_a
    above: 2
conditions: []
actions:
  - action: notify.mobile_app_paddy_iphone
    metadata: {}
    data:
      message: The Pump Turned On
  - action: notify.persistent_notification
    metadata: {}
    data:
      message: The pump turned on
      data:
        timestamp: "{{ now().timestamp() }}"
mode: single

but this doesn’t work

You can’t just make things up… There are only 3 configuration variables allowed under data for persistent notifications.

Your options are to add a timestamp to the title or message.

action: notify.persistent_notification
metadata: {}
data:
  message: The pump turned on
  title: "{{ now() }}"
action: notify.persistent_notification
metadata: {}
data:
  message: The pump turned on at {{now()}}
1 Like