Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95533

Automatic Battery Date Tracker Help

$
0
0

@Bartem wrote:

So I was trying to keep better track of how long my batteries were lasting in some devices… so I made a bunch of input_datetimes and an automation to update them when the corresponding battery levels are 100.
That all seemed to work fine for my devices that update the battery levels regularly… I didn’t mind if the date was off a few days/week until it dropped to 99.
The issue I didn’t really think of was some of my devices only update when the change is like 10% some possibly 30% (some of my zigbee contact sensors)
The problem comes up that after a reboot it is changing the date again, which with the devices that don’t update battery level often it will start to throw the dates pretty far off…
Anyone have any idea how I could prevent it from updating the input_datetime after the initial time it triggers at 100? I was trying to do this as one automation so adding a condition to the automation would prevent the whole thing from firing… so I was hoping I could somehow manage that with the template. I suppose if not my plan would be to split out the automation to devices that update regularly and those that don’t with a condition to see that last time the input_datetime was changed… I think?? :roll_eyes:
Here is the automation:

- alias: Set Battery Changed Datetimes
  trigger:
    - platform: numeric_state
      entity_id:
        - sensor.front_door_lock_battery_level
        - sensor.side_door_lock_battery_level
        - sensor.garage_door_lock_battery_level
        - sensor.bedroom_contact_sensor_battery
        - sensor.sump_pump_alarm_battery_level
        - sensor.front_door_sensor_battery
        - sensor.front_doorbell_sensor_battery       
        - sensor.side_door_sensor_battery
        - sensor.side_doorbell_sensor_battery
        - sensor.scene_switch_battery_level
        - sensor.multisensor_battery_level
      above: 99
      for:
        minutes: 10
  action:
    - service: input_datetime.set_datetime
      data_template:
        entity_id: >
          {% if trigger.entity_id == 'sensor.front_door_lock_battery_level' %}
            input_datetime.front_door_lock_batteries
          {% elif trigger.entity_id == 'sensor.side_door_lock_battery_level' %}
            input_datetime.side_door_lock_batteries
          {% elif trigger.entity_id == 'sensor.garage_door_lock_battery_level' %}
            input_datetime.garage_door_lock_batteries
          {% elif trigger.entity_id == 'sensor.bedroom_contact_sensor_battery' %}
            input_datetime.bedroom_contact_sensor_battery
          {% elif trigger.entity_id == 'sensor.sump_pump_alarm_battery_level' %}
            input_datetime.sump_pump_alarm_battery
          {% elif trigger.entity_id == 'sensor.front_door_sensor_battery' %}
            input_datetime.front_door_sensor_battery
          {% elif trigger.entity_id == 'sensor.front_doorbell_sensor_battery' %}
            input_datetime.front_doorbell_sensor_battery
          {% elif trigger.entity_id == 'sensor.front_door_sensor_battery' %}
            input_datetime.side_door_sensor_battery
          {% elif trigger.entity_id == 'sensor.front_doorbell_sensor_battery' %}
            input_datetime.side_doorbell_sensor_battery
          {% elif trigger.entity_id == 'sensor.scene_switch_battery_level' %}
            input_datetime.scene_switch_battery
          {% elif trigger.entity_id == 'sensor.multisensor_battery_level' %}
            input_datetime.multisensor_battery
          {% endif %}
        date: "{{ as_timestamp(now())|timestamp_custom('%Y-%m-%d') }}"

Posts: 6

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 95533

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>