Sleep as Android and MQTT

I’ve been finding the Android app’s alarm integration to be spotty lately (I think the integration with SaA and the openHAB app is challenging) and I decided to implement this MQTT approach as a stop-gap (or maybe a permanent solution).

As I was following the guide, I wonder if it makes more sense to configure as a Trigger Channel as opposed to a String Channel. The messages published from SleepAsAndroid represent an event, not a state (though you could convert some of the start/stop paired events to a state). But if all you care about is the start of the alarm, you can treat that as an event.

If all you care about is the one event, just trigger the rule using a Thing trigger event (you don’t even need to check which one). If you do care, you can limit it to the “alarm_alert_start” event in the trigger or you can set up the transformation on the Channel to create a separate Channel for each event you care about (see MQTT 2.5 M1+ How to implement the equivalent to MQTT1 REGEX filters, though I think there’s a way to do it just using the JSONPATH transform).

I set it up as follows:

MQTT Trigger Channel:

UID: mqtt:topic:broker:sleepasandroid
label: SleepAsAndroid
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:broker
location: Phone
channels:
  - id: event
    channelTypeUID: mqtt:trigger
    label: Event
    description: ""
    configuration:
      stateTopic: SleepAsAndroid
      transformationPattern: JSONPATH:$.event

Rule Trigger:

configuration: {}
triggers:
  - id: "2"
    configuration:
      thingUID: mqtt:topic:broker:sleepasandroid
      channelUID: mqtt:topic:broker:sleepasandroid:event
      event: alarm_alert_start
    type: core.ChannelEventTrigger

Like you, I have a morning routine that runs but only if it’s not already past sunrise.