Skip to content

IATkachenko/HA-SleepAsAndroid

Repository files navigation

version_badge Validate with hassfest hacs_badge Custom badge

Sleep As Android custom integration

This integration will allow you to get events from your SleepAsAndroid application in a form of the sensor states and events in Home assistant.

Installation & configuration

Requirements

You will need:

Installation

  • go to HACS -> Integrations
  • press + Explore & Add repositories button
  • type Sleep As Android in search field and click at integration name
  • press Install this repository to HACS button
  • press Install button (if you have outdated version of Home Assistant -- check integration version in Wiki )
  • restart Home Assistant
  • go to Home Assistant Settings -> Integrations -> Add Integration (right bottom conner)
  • type Sleep As Android in search field and click at integration name. Clean browser cache if nothing found.

Configuration

Component configuration

  • Name: name of the device/sensor and a prefix for the events. Will be used as a default prefix for devices and events.
  • Topic template: template for MQTT topic where Sleep as Android will publish event. %%%device%%% may be used in template to point to device name position. Examples:
    • SleepAsAndroid/igor - no %%%device%%% in template just one device will be tracked and one device will be created for HomeAssistant
    • SleepAsAndroid/%%%device%%% - all sub topics in SleepAsAndroid/ will be recognized as devices
    • devices/%%%device%%%/SleepAsAndroidData - all subtopic in devices/ will be used as devices, data will be taken from /SleepAsAndroidData for every device, ie devices/igor/SleepAsAndroidData for device igor
  • QOS: quality of service for MQTT

Application configuration

To configure Sleep As Android for working with this integration:

  1. Go to application settings
  2. Find Services in integration section
  3. Go to Automation
  4. Find MQTT section

Then:

  • Enable it
  • URL is a URL for your MQTT server. It should look like tcp://mqtt_user:mqtt_password@mqtt_host:mqtt_port
  • Topic is a topic name where the application will publish events. See Topic template section of component configuration for details. Application settings MUST NOT have %%%device%%% macro. Use desired device name at position of %%%device%%% of integration configuration. Examples related to integration configuration above: SleepAsAndroid/igor or devices/igor/SleepAsAndroidData. Device name will be "igor" in both cases.
  • Client ID is any ID. It is not used by integration and is not published to MQTT (now).

SleepAsAndroid configuration

More details in Wiki.

Usage

blueprint (recommended)

  1. import blueprint:
    1. Got to Home Assistant settings
    2. blueprints
    3. import blueprint button
    4. put blueprint URL
    5. press preview button
    6. press import button
  2. create automatization based on blueprint:
    • person and state is using to run actions only if person in state (to avoid run home automatization related to sleep tracking while vacation in Siberia, for example)
    • add actions for evens

on device event

  1. select Device in automatization trigger and use SleepAsAndroid device;
  2. select trigger from a list.

added_in_version_badge events will be fired up for every MQTT message

on sensor state change

<name> is an integration name in lower case without spaces from the Settings dialog. <device> is a device name List of events is available at Sleep As Android documentation page

State of sensor sensor.<name>_<device> will contain the recent event name, that got published by the application.

on event

<name> is an integration name in lower case without spaces from the Settings dialog. If application publishes a new event, then integration fires <name> event with payload:

{
  "event": "<event_name_from_application>"
}

added_in_version_badge events will be fired up for every MQTT message

Attributes

added_in_version_badge

Sensor have additional attributes:

  • timestamp -- value1 from application event. It is usually timestamp of something. Meaning is depended on event. Please check Sleep As Android events documentation for more details;
  • label -- value2 from application event. It is usually alarm label. You can use this attribute to tell one alarm from another.

If event have no value<N> field, then attribute will be set to unknown.

Troubleshooting

configuration.yaml:

logger:
  default: warning
  logs:
    custom_components.sleep_as_android: debug