Numeric_state question

When it comes to numeric_state, I have some vacuum sensors listed such as vacuum.replace_filter.

When vaccum is docked for 1 hour and vacuum.replace_filter below 0 then send a notification.

In order for this to work, does vacuum.replace_filter need to be included in the recorder?

It should be okay to exclude it from recorder: to check the current state or trigger on the state of that entity. In this case, you’d want an automation that looks like:

trigger:
  platform: state
  entity_id: vacuum.sucker
  to: 'docked'
  for: "01:00:00"
condition:
  condition: numeric_state
  entity_id: vacuum.replace_filter
  below: 0
action:
  service: notify.something
  data:
    message: Replace filter

And it will just check the current state in the condition.

Thanks!

Basically that’s what I have, though my notifications are still not firing. My sensor value comes back as a decimal - sensor.vac2_replace_side_brush = -5.5

  trigger:
    platform: state
    entity_id:
      - vacuum.vac1
      - vacuum.vac3
      - vacuum.vac2
    to: 'docked'
    for: '00:01:00'
  condition:
    - condition: numeric_state
      entity_id:
        - sensor.vac1_replace_main_brush
        - sensor.vac3_replace_main_brush
        - sensor.vac2_replace_main_brush
        - sensor.vac1_replace_side_brush
        - sensor.vac3_replace_side_brush
        - sensor.vac2_replace_side_brush
        - sensor.vac1_replace_filter
        - sensor.vac3_replace_filter
        - sensor.vac2_replace_filter
        - sensor.vac1_clean_sensors
        - sensor.vac3_clean_sensors
        - sensor.vac2_clean_sensors
      below: 0
  action:
    - service: notify.bullet
      data:
        title: "Vacuum Maintenance"
        message: "{{ state_attr(trigger.entity_id, 'friendly_name') }}"

And the sensor:

 vac2_replace_filter: 
    friendly_name: Replace Filter
    unit_of_measurement: 'h'
    value_template: "{{ (states('sensor.vac2_filter_left')|float(0) / 3600) | round(1) }}"
    icon_template: 'mdi:screwdriver'

Conditions are always “and” unless you explicitly make them “or”, and listing a bunch of entities like that will always be “and”. You could do that much easier with a template:

    - condition: template
      value_template: "{{ states.sensor|selectattr('entity_id', 'match', 'sensor.vac.*_(replace|clean)')|map(attribute='state')|map('float')|select('lt', 0)|list|length > 0}}"
1 Like

If you were to break use the conditional I had, what would be the way to code that?

LIke this? See the second example here for what your code is doing.

Looking at the second example you provided, that is what I’m doing as shown in the code listed in post 3. Am I missing something?

Try this:

  trigger:
    platform: state
    entity_id:
      - vacuum.vac1
      - vacuum.vac3
      - vacuum.vac2
    to: 'docked'
    for: '00:01:00'
  condition:
    - condition: template
      value_template: >
        {{ [ states('sensor.' ~ trigger.to_state.object_id ~ '_replace_main_brush') | int(0) ,
             states('sensor.' ~ trigger.to_state.object_id ~ '_replace_side_brush') | int(0),
             states('sensor.' ~ trigger.to_state.object_id ~ '_replace_filter') | int(0),
             states('sensor.' ~ trigger.to_state.object_id ~ '_clean_sensors') | int(0)]
           | select ('lt', 0) | list | count > 0 }}
  action:
    - service: notify.bullet
      data:
        title: "Vacuum Maintenance"
        message: "{{ state_attr(trigger.entity_id, 'friendly_name') }}"

EDIT

Correction. Overlooked to include the entity’s domain.

Yes, it’s what you’re doing. And because specifying all the entities in a list like that requires all of them to satisfy the condition at once (an “and”), it’s not doing what you want. You want an “or”, which either my template or Taras’s example will do. Or, as mentioned in the first link I posted, you can create a whole bunch of separate conditions and nest them under an “or” condition. That’s a lot of extra typing, though.