RobertD502 / home-assistant-flair

Custom component for Home Assistant Core for Flair pucks, vents, rooms, structures, and minisplits
MIT License
92 stars 12 forks source link

[Request] Add `history_stats` for each vent's connection state #87

Open ptr727 opened 8 hours ago

ptr727 commented 8 hours ago

I added an automation to monitor vent online/offline state, and I added history_stats for a couple vents to monitor how often they are offline.

The notification is pretty easy for I do it for any connected device (with your prior help to add the state), but I have not found a way to do history_stats without manually creating an entry for every single vent.

I am wondering if it is possible to add a history_stats or some other sensor to be able to report on disconnected time per period, e.g. offline time per week, for every vent?

History stats sensor:

# TODO: Add for all vents
- platform: history_stats
  type: time
  name: "Dining Room Vent Disconnected"
  # TODO: Unique id not supported?
  # unique_id: dining_room_9925_disconnected
  entity_id: binary_sensor.dining_room_9925_connection_status
  state: "off"
  start: "{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}"
  end: "{{ now() }}"

Blueprint for connectivity state change notifications:

blueprint:
  name: Device connectivity state alert
  description: Send a notification when a device connectivity state change triggers
  domain: automation
  author: https://github.com/ptr727

  input:

    exclude:
      name: Excluded sensors
      description: Sensors to exclude
      default:
        entity_id: []
      selector:
        target:
          entity:
            device_class: connectivity

    actions:
      name: Actions to take
      description: E.g. Device connectivity change reported by {{ trigger.event.data.new_state.attributes.friendly_name }}
      selector:
        action: null

mode: single

triggers:
  - trigger: event
    event_type: state_changed

condition:
  condition: template
  value_template: >-
    {{ trigger.event.data.new_state.attributes.device_class == "connectivity"
    and trigger.event.data.old_state.state != trigger.event.data.new_state.state }}

action:
- choose: []
  default: !input actions

Thank you

RobertD502 commented 5 hours ago

No, sorry. History stats is an integration of its own and not a type of entity available for developers to create. When it comes to wanting very specific stats like that, you'll have to create history stats sensors manually.

Shouldn't be that big of a time suck considering you can copy paste your code and just change the name and entity id.

ptr727 commented 5 hours ago

Ok, too bad, was hoping there is a way for a custom component to create other integrations.