Home Assistant

From Hackerspace ACKspace
Jump to: navigation, search

synopsis

This page shows some snippets to to improve upon your Home Assistant installation.

SpaceAPI

Example screenshot of HA dashbord created by the code below: Home Assistant dashboard.png

configuration.yaml

xopr is not sure what syntax (legacy or new) is used (frankly, the HA logic and templating system is a mess and he couldn't care less). The result is that it is unclear if sensors could be generated from a for loop, if attributes (like lastchange) could be set, whether something simpeler than wrapping Markdown around some data to show a dynamic image, and so forth.

Update this code if you think you know better. I've searched the forum all evening and mostly found the Gudim meme one way or another; currently this is a "Works for me™" solution..

rest:
  - scan_interval: 60
    resource: https://ackspace.nl/spaceAPI/
    method: GET
    
    binary_sensor:
      - name: "ACKspace spacestate alt"
        value_template: "{{ iif(value_json.state.open, 'Open', 'Closed', 'Unknown') }}"

    sensor:
      - name: "ACKspace spacestate"
        value_template: "{{ iif(value_json.state.open, 'Open', 'Closed', 'Unknown') }}"
      - name: "ACKspace spacestate lastchange"
        value_template: "{{ value_json.state.lastchange | int (0) | timestamp_custom('%H:%M:%S (%d %b)')}}"
      - name: "ACKspace spacestate message"
        value_template: "{{ value_json.state.message }}"

      - name: "ACKspace spacestate image"
        value_template: >
            {% if value_json.state.open %}
              {{value_json.state.icon.open}}
            {% else %}
              {{value_json.state.icon.closed}}
            {% endif %}
      - name: "ACKspace external IP"
        value_template: "{{ value_json.ext_ip }}"

      - name: "stACKspace servers"
        value_template: "{{ value_json.sensors.temperature[0].value }}"
        unit_of_measurement: °C
      - name: "stACKspace lastchange"
        value_template: "{{ value_json.sensors.temperature[0].ext_lastchange | int (0) | timestamp_custom('%H:%M:%S (%d %b)')}}"
      - name: "stACKspace"
        value_template: "{{ value_json.sensors.temperature[1].value }}"
        unit_of_measurement: °C
      - name: "ACKspace Outside"
        value_template: "{{ value_json.sensors.temperature[2].value }}"
        unit_of_measurement: °C

      - name: "hACKspace desk area"
        value_template: "{{ value_json.sensors.power_consumption[0].value }}"
        unit_of_measurement: W
      - name: "hACKspace printer corner"
        value_template: "{{ value_json.sensors.power_consumption[1].value }}"
        unit_of_measurement: W
      - name: "slACKspace media corner"
        value_template: "{{ value_json.sensors.power_consumption[2].value }}"
        unit_of_measurement: W
      - name: "slACKspace food corner"
        value_template: "{{ value_json.sensors.power_consumption[3].value }}"
        unit_of_measurement: W
      - name: "hACKspace solder corner"
        value_template: "{{ value_json.sensors.power_consumption[4].value }}"
        unit_of_measurement: W

Example raw dashboard

Do note that there are several versions of the spacestate on this dashboard; I'm still looking to see which one does state history better.

views:
  - title: Home
    cards:
      - type: entity
        entity: sensor.ackspace_spacestate
      - type: entity
        entity: sensor.ackspace_external_ip
      - type: entities
        entities:
          - entity: sensor.stackspace
          - entity: sensor.stackspace_servers
          - entity: sensor.ackspace_outside
      - type: entities
        entities:
          - entity: sensor.hackspace_solder_corner
          - entity: sensor.hackspace_desk_area
          - entity: sensor.hackspace_printer_corner
          - entity: sensor.slackspace_media_corner
          - entity: sensor.slackspace_food_corner
      - type: entity
        entity: binary_sensor.ackspace_spacestate_alt
        icon: ''
      - type: markdown
        content: >+
          [![image]({{states('sensor.ackspace_spacestate_image')}})](https://ackspace.nl/spaceAPI/statechanges.html)

          {{states('sensor.ackspace_spacestate_message')}} since
          {{states('sensor.ackspace_spacestate_lastchange')}}