Sleep as Android added support for Webhooks and MQTT

I was just looking into a replacement for IFTTT to get events from Sleep as Android to HA when I found this:
[COMPLETE] Webhooks without IFTTT

Their latest beta builds include support for custom webhooks and MQTT!
It shouldn’t take long to be available in Play store.
I will for sure start using the new webhook feature soon.

3 Likes

yup its awesome, been using it to push states to input_text for now

Are you using the beta channel?
I’m just considering if I should switch to that.

I have been on the beta builds since I started using the app

So far this is what I have, not anything special but it does its thing.

  1. Setup a webhook: https://www.home-assistant.io/docs/automation/trigger/#webhook-trigger
  2. In sleep as android configure the webhook to point to the new webhook you created.
  3. Create an input_text helper in HA

Here is the quick YAML:

- alias: Sleep as android webhook
  trigger:
    platform: webhook
    webhook_id: !secret sleep_as_android_webhook
  action:
  - service: input_text.set_value
    data:
      entity_id: input_text.sleep_as_android
      value: "{{ trigger.json.event }}"

The state will change to the event name as outlined in their documentation. Lets see if others come up with unique ways to create sensors and what not :slight_smile:

5 Likes

I tried setting up the mqtt integration but ‘OK’ stays greyed out when I put in my mqtt server address.

I went with the webhooks because my MQTT server is not externally facing so not sure, its a beta feature so may need to report the bug so the dev can fix it.

I ended up setting up the webhook integration as well. And I reported it in the beta tester section of their forum.

Hello, I’m the developer of Sleep as Android, sorry fro the issues. We did not yet test the MQTT feature as it is now BETA and we are waiting for feedback. Can you please let me know the URL of your MQTT server you can’t type in the field? Big thanks for your help…

3 Likes

Many thanks for pointing the MQTT URL entry issue out. I was able to reproduce this and a fix is heading to BETA just now… many thanks, please let us know if this new feature is working for you…

6 Likes

Hi all.

I had made custom integration for MQTT way https://github.com/IATkachenko/HA-SleepAsAndroid.
Try it, if you prefer (like me) MQTT than webhooks solution described above.

3 Likes

This is great, my only issue is my MQTT server is not exposed externally so I opted to do a webhook. I was actually trying to think of a way to make an integration that would work with the webhook, but for now the automation with input_text works perfect :slight_smile:

is there any more detailed guide how to setup the MQTT Sever, Webhooks and the Sleep as Android client without HACS all at once?

I tried to make it work by reading about it individually yet cant make it work

Did you follow these steps I highlighted earlier? Sleep as Android added support for Webhooks and MQTT - #5 by dshokouhi

If you got stuck let us know how you got stuck so we can help you.

If you do not have a MQTT server setup that will be more difficult and a webhook may work better for you.

yes i saw your instructions and followed the links.

I tried to make it work, but honestly i cannot make a lot of sense of the individual parts of the configuration.

I dont understand which parts are individual for each setup, like webhook id etc. that needs to be adjusted manually.

I step by step guide would be necessary and well appreciated.

Hi,
I’m trying to get this working to trigger a light to slowly brighten over 30 minutes. I have everything working except the webhook. I can make it trigger using curl POST but can’t get it to trigger from Sleep As Android (SAA). I think it’s because SAA is sending JSON data and the webhook is just expecting a POST. How do I get it to accept “ALARM_ALERT_START” as the trigger? It’s the only event I need to track. Sorry if I’m not quite using the right terminology, I’ve only just started using HA and I’ve never used webhooks before!
Thanks
Michael
[edit] I’m an idiot, the URL is case sensitive so when my phone was autocorrecting /api/webhook to /API/webhook it was breaking everything!

@Vin2 All you need to do is setup a automation with a new webhook path. From there you can process the data as you wish. Here is an example that I am using where all I am doing is storing the event names in a input_text so I can use them in other automations. I only update this input_text via this automation.

- alias: Sleep as android webhook
  trigger:
    platform: webhook
    webhook_id: MY_RANDOM_WEBHOOK_ID
  action:
  - service: input_text.set_value
    data:
      entity_id: input_text.sleep_as_android
      value: "{{ trigger.json.event }}"

So all you need to do is create a input_text helper and replace MY_RANDOM_WEBHOOK_ID with anything you want.

Then in sleep as android you go to settings > services > automation > webhooks and enter a URL similar to

https://www.example.com/api/webhook/MY_RANDOM_WEBHOOK_ID

Just make sure to use your domain or nabu casa remote URL to replace www.example.com and then replace MY_RANDOM_WEBHOOK_ID with whatever you used in your automation.

Remember to update the entity ID of the input_text helper you ahve created

some links to help out, I also included a secrets link in case that confused you with earlier instructions. make sure to read all the links too all the answer you seek are there.

https://www.home-assistant.io/integrations/input_text/
https://www.home-assistant.io/docs/automation/trigger/#webhook-trigger
https://www.home-assistant.io/docs/configuration/secrets/
https://docs.sleep.urbandroid.org/services/custom_webhooks.html

1 Like

Hi can you give me a configuration exemple of mqtt for sleep as android ti integrate sensor??thanks you. I tryed to do a sensor but state Is Always unknown. I write in this mode:

  • platform: mqtt
    name: Apnea
    state_topic: “SleepAsAndroi/sonno/apnea_alarm”

You have a ‘d’ missing in the topic

A d missing??