jazzyisj/unavailable-entities-sensor

Ignore Seconds from unavailable to available

Closed this issue · 4 comments

Hi. Thanks for this useful code.

When I set "ignore_seconds" to 300 then I get notification after 300 seconds when an entity becomes unavailable. But after an entity becomes available again I get notification approximately within 1 minute.

Is it possible to change the code to make "ignore" time the same for available and unavailable states?

The issue you describe is caused by your automation triggers, not the value of the unavailable entities sensor.

Basically, you want to throttle your automation. Can you post your automation YAML here? I'll give you a hand figuring it out.

- id: unavailable_entities_notify_telegram
  alias: Unavailable Entities => Notify - Telegram
  mode: restart
  trigger:
  - platform: state
    entity_id: sensor.unavailable_entities
    attribute: entity_id
    to:
  condition:
  - condition: template
    value_template: "{{ is_number(trigger.from_state.state) and is_number(trigger.to_state.state) }}"
  action:
  - if:
    - condition: numeric_state
      entity_id: sensor.unavailable_entities
      below: 1
    then:
    - service: notify.telegram
      data:
        message: '*Unavailable Entities*

          0'
    else:
    - service: notify.telegram
      data:
        message: '{% set trigger_data = state_attr(''sensor.unavailable_entities'',''entity_id'')|join(''\n- '') %}

          *Unavailable Entities*

          - {{ trigger_data.replace(''_'',''\_'') }}'

Add this condition to the condition block. This will prevent your automation from running more than once every 5 minutes. Make sure the entity id for the automation is correct.

- condition: template
  value_template: "{{ now() - states.automation.unavailable_entities_notify_telegram.attributes.last_triggered > timedelta(seconds=300) }}"

Also when pasting code, right click and "paste as plain text" then format your code by selecting the code block and clicking the "Add Code" button. Makes it much easier to read.
image

If my suggestion worked for you please come back and close the issue! Thanks!

I use such condition in some of my automations. I thought there is more "elegant" solution)

I'll try to follow github guidelines) Thank you for your help!