Skip to content
caiosweet edited this page Jun 25, 2023 · 3 revisions

Sensor

Here you find other sensors that are not strictly related to the package, but which I use in some example automations.

Sensor Home Assistant Start

command_line:
#------------------------------------------------------------------------------#
# Home Assistant initialized sesnor
#------------------------------------------------------------------------------#
  - sensor:
      name: HA Start
      command: >
        grep -m1 'Home Assistant initialized' home-assistant.log 
        | awk '{ print $6, $7, $8, $9, $10 }'
      value_template: '{{ value | default("Error", true) }}'
      scan_interval: 525600 # 1 year

      # If you only want seconds as sensor state, then use this:
      # command: >
      #   grep -m1 'Home Assistant initialized' home-assistant.log | awk '{ print $10 }'

## In order to use sensor.ha_start, set the info logs in this way

logger:
  default: warn
  logs:
    homeassistant.bootstrap: info
# Sensor Last Alexa based on the group.notifier_player_alexa
template:
  - sensor:
      - name: last alexa
        unique_id: last_alexa
        state: >
          {{ expand(states.group.notifier_player_alexa) 
          | selectattr('attributes.last_called', 'eq', True) 
          | map(attribute = 'entity_id') 
          | first }}
        availability: >
          {{ expand(states.group.notifier_player_alexa) | selectattr('attributes.last_called','eq',True) | first is defined }}
Clone this wiki locally