# Home Assistant posts to a Botopticon board.
# Put the ingest token in secrets.yaml:
#   botopticon_ingest: "Bearer <INGEST_TOKEN>"
# Then reload REST commands.

rest_command:
  botopticon_status:
    url: "https://www.botopticon.com/api/ingest"
    method: POST
    headers:
      authorization: !secret botopticon_ingest
    content_type: "application/json"
    payload: '{"bot":"Home","tile":"house","type":"status","title":"House","subtitle":"Home Assistant","props":{"state":"routine","task":"Keeping the board current"},"needs_you":false,"ttl_seconds":3600}'
  botopticon_power:
    url: "https://www.botopticon.com/api/ingest"
    method: POST
    headers:
      authorization: !secret botopticon_ingest
    content_type: "application/json"
    payload: >
      {{ {"bot":"Home","tile":"power","type":"kpi","title":"Power","subtitle":"House meter","props":{"value": states('sensor.house_power')|float(0), "unit":"W"}, "needs_you": false, "ttl_seconds": 3600} | tojson }}

automation:
  - alias: Post house status to the Botopticon board
    triggers:
      - trigger: time_pattern
        minutes: "/30"
    actions:
      - action: rest_command.botopticon_status
  - alias: Post house power to the Botopticon board
    triggers:
      - trigger: time_pattern
        minutes: "0"
    actions:
      - action: rest_command.botopticon_power
