Skip to content

Instantly share code, notes, and snippets.

@TheQue42
Last active July 6, 2022 12:13
Show Gist options
  • Select an option

  • Save TheQue42/b959d6ed3412b8d947fa3d03e4e6babb to your computer and use it in GitHub Desktop.

Select an option

Save TheQue42/b959d6ed3412b8d947fa3d03e4e6babb to your computer and use it in GitHub Desktop.

Revisions

  1. TheQue42 revised this gist Jul 6, 2022. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions BatteryTemp.yaml
    Original file line number Diff line number Diff line change
    @@ -25,10 +25,9 @@ blueprint:
    Only entities are supported, devices must be expanded
    default: []
    selector:
    entity:
    multiple: true
    domain:
    - sensor
    target:
    entity:
    device_class: temperature
    exclude_regexp:
    name: Excluded Sensors, RegExp
    description: >
  2. TheQue42 revised this gist Jul 6, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion BatteryTemp.yaml
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    blueprint:
    name: BP: Battery Temp Checker
    name: BP-Battery Temp Checker
    description: Regularly test any entity with the "battery" string, for high temp!
    domain: automation
    input:
  3. TheQue42 revised this gist Jul 6, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion BatteryTemp.yaml
    Original file line number Diff line number Diff line change
    @@ -49,7 +49,7 @@ variables:
    sensors: >-
    {%- set result = namespace(sensors=[]) -%}
    {%- for s in states.sensor | selectattr('attributes.device_class', '==', 'temperature') -%}
    {%- if (s.entity_id is search("battery") and (not s.entity_id in exclude and not s.entity_id is search(exclude_regexp))) and s.state|float > max_temp|float -%}
    {%- if (s.entity_id is search("battery") and (not s.entity_id in exclude and not s.entity_id is search(exclude_regexp))) and s.state|float > max_value|float -%}
    {%- set result.sensors = result.sensors + [s.entity_id] -%}
    {% endif -%}
    {%- endfor -%}
  4. TheQue42 revised this gist Jul 6, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion BatteryTemp.yaml
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    blueprint:
    name: Battery temperatur checker
    name: BP: Battery Temp Checker
    description: Regularly test any entity with the "battery" string, for high temp!
    domain: automation
    input:
  5. TheQue42 revised this gist Jul 6, 2022. No changes.
  6. TheQue42 revised this gist Jul 6, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions BatteryTemp.yaml
    Original file line number Diff line number Diff line change
    @@ -48,8 +48,8 @@ variables:
    max_value: !input 'max_temp'
    sensors: >-
    {%- set result = namespace(sensors=[]) -%}
    {%- for s in states.sensor -%}
    {%- if (s.entity_id is search("battery") and state_attr(s.entity_id, "device_class") == "temperature" ) and (not s.entity_id in exclude and not s.entity_id is search(exclude_regexp)) and s.state|float > max_temp|float -%}
    {%- for s in states.sensor | selectattr('attributes.device_class', '==', 'temperature') -%}
    {%- if (s.entity_id is search("battery") and (not s.entity_id in exclude and not s.entity_id is search(exclude_regexp))) and s.state|float > max_temp|float -%}
    {%- set result.sensors = result.sensors + [s.entity_id] -%}
    {% endif -%}
    {%- endfor -%}
  7. TheQue42 revised this gist Jul 6, 2022. 1 changed file with 13 additions and 10 deletions.
    23 changes: 13 additions & 10 deletions BatteryTemp.yaml
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    blueprint:
    name: Unavailability Detector
    description: Regularly test all sensors for unavailability or "unknown"-ness.
    name: Battery temperatur checker
    description: Regularly test any entity with the "battery" string, for high temp!
    domain: automation
    input:
    repetition:
    @@ -10,6 +10,14 @@ blueprint:
    selector:
    text:
    multiline: false
    max_temp:
    name: Max Temp
    description: Temperature at which alarm is generated
    default: '40'
    selector:
    number:
    min: 20
    max: 80
    exclude:
    name: Excluded Sensors
    description: >
    @@ -20,7 +28,6 @@ blueprint:
    entity:
    multiple: true
    domain:
    - binary_sensor
    - sensor
    exclude_regexp:
    name: Excluded Sensors, RegExp
    @@ -32,24 +39,20 @@ blueprint:
    multiline: false
    actions:
    name: Actions
    description: 'Notifications or similar to be run. {{sensors}} is replaced with the names[] of devices indicating a problem.'
    description: 'Notifications or similar to be run. {{sensors}} is replaced with the names[] of devices indicating high temp'
    selector:
    action: {}
    variables:
    exclude: !input 'exclude'
    exclude_regexp: !input 'exclude_regexp'
    max_value: !input 'max_temp'
    sensors: >-
    {%- set result = namespace(sensors=[]) -%}
    {%- for s in states.sensor -%}
    {%- if s.state is search("unavail|unknown") and (not s.entity_id in exclude and not s.entity_id is search(exclude_regexp)) -%}
    {%- if (s.entity_id is search("battery") and state_attr(s.entity_id, "device_class") == "temperature" ) and (not s.entity_id in exclude and not s.entity_id is search(exclude_regexp)) and s.state|float > max_temp|float -%}
    {%- set result.sensors = result.sensors + [s.entity_id] -%}
    {% endif -%}
    {%- endfor -%}
    {%- for s in states.binary_sensor -%}
    {%- if s.state is search("unavail|unknown") and (not s.entity_id in exclude and not s.entity_id is search(exclude_regexp)) -%}
    {%- set result.sensors = result.sensors + [s.entity_id] -%}
    {%- endif -%}
    {%- endfor -%}
    {{result.sensors}}
    trigger:
    - platform: time_pattern
  8. TheQue42 created this gist Jul 6, 2022.
    62 changes: 62 additions & 0 deletions BatteryTemp.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    blueprint:
    name: Unavailability Detector
    description: Regularly test all sensors for unavailability or "unknown"-ness.
    domain: automation
    input:
    repetition:
    name: How often to run
    description: Test is run at this intervall, in minutes. You MUST use the slash notation; 0-59 minutes.
    default: '/30'
    selector:
    text:
    multiline: false
    exclude:
    name: Excluded Sensors
    description: >
    There are some weird sensors out there, we might want to ignore.
    Only entities are supported, devices must be expanded
    default: []
    selector:
    entity:
    multiple: true
    domain:
    - binary_sensor
    - sensor
    exclude_regexp:
    name: Excluded Sensors, RegExp
    description: >
    There are some weird sensors out there, we might want to ignore.
    default: 'DontMatchAnySensorsAtAll'
    selector:
    text:
    multiline: false
    actions:
    name: Actions
    description: 'Notifications or similar to be run. {{sensors}} is replaced with the names[] of devices indicating a problem.'
    selector:
    action: {}
    variables:
    exclude: !input 'exclude'
    exclude_regexp: !input 'exclude_regexp'
    sensors: >-
    {%- set result = namespace(sensors=[]) -%}
    {%- for s in states.sensor -%}
    {%- if s.state is search("unavail|unknown") and (not s.entity_id in exclude and not s.entity_id is search(exclude_regexp)) -%}
    {%- set result.sensors = result.sensors + [s.entity_id] -%}
    {% endif -%}
    {%- endfor -%}
    {%- for s in states.binary_sensor -%}
    {%- if s.state is search("unavail|unknown") and (not s.entity_id in exclude and not s.entity_id is search(exclude_regexp)) -%}
    {%- set result.sensors = result.sensors + [s.entity_id] -%}
    {%- endif -%}
    {%- endfor -%}
    {{result.sensors}}
    trigger:
    - platform: time_pattern
    minutes: !input 'repetition'
    condition:
    - '{{ sensors|length != 0 }}'
    action:
    - choose: []
    default: !input 'actions'
    mode: single