MQTT support

client-apps
home-automation
integration
Tags: #<Tag:0x00007f2712fe0340> #<Tag:0x00007f2712fe0110> #<Tag:0x00007f271258bea8>

#1

New firmware with MQTT support is ready for testing!
Those interested in early access, please Please PM me your device IDs.

After the firmware has been updated over-the-air, please access configuration interface:

  1. Put your unit into listening mode: press and hold “M” button for about 3 seconds until LED starts blinking dark blue.
  2. Connect any WiFi enabled device to PHOTON-XXXX access point.
  3. Open http://192.168.0.1/ in the browser and (re-)configure WiFi connection and MQTT settings
  4. Submit to save. The device will reconnect to your WiFi network.

This process can be repeated anytime if necessary. Internet connection is not required.
Note that either or both Cloud and MQTT links can be used.
This firmware can be reversed if something doesn’t work out right.
The code was tested with Mosquitto broker, but should work with Home Assistant or any other standard MQTT client.


#2

What are the MQTT command topics?


#3

Following topics are supported:

/garadget/{device-name}/status
/garadget/{device-name}/command

{device-name} is configured in the setup
First topic is used by Garadget to send the door status updates (you’ll received open/closed/stopped as payload)
Second is used by Garadget to receive door commands (you can send open/close/stop)


#4

If you are a home assistant user the configuration in HA will look like this:

cover:

  • platform: mqtt
    name: "Garage Door"
    command_topic: "garadget/device_name/command"
    state_topic: "garadget/device_name/status"
    payload_open: "open"
    payload_close: “close”

Status Sensor:

  • platform: template
    sensors:
    garage_door_status:
    friendly_name: 'Garage Door State’
    value_template: '{{ states.cover.garage_door.state }}'
    icon_template: ‘{% if is_state(“cover.garage_door”, “closed”) %}mdi:garage{% else %}mdi:garage-open{% endif %}’

#5

New Version!

New firmware version with MQTT support is ready for testing. I fixed some issues and made some stability improvements. Please PM your device IDs for over-the-air firmware update to the new version.

Change Log

  • Recent versions of Home Assistant’s internal MQTT broker users protocol version 3.1.1 which expects a different handshake from the client and rejects the connection otherwise. The new version of firmware alternately tries to connect using protocol v3.1 and v3.1.1 until succeeds.
  • Added light brightness sensor in case somebody wants to use in automation or just for reporting
  • Implemented device configuration via MQTT calls with JSON payloads
  • Updated payload formats for some of the calls
  • Sensor reads parameter deprecated in UI and hard-coded at 3.

Initial Configuration

After you confirmed in settings that your Garadget is at at v1.19 use the following process to configure MQTT connection.

  1. Put your unit into listening mode: press and hold “M” button for about 3 seconds until LED starts blinking dark blue.
  2. Connect any WiFi enabled device to PHOTON-XXXX access point.
  3. Open http://192.168.0.1/ in the browser and (re-)configure WiFi connection and MQTT settings
  4. Submit to save. The device will reconnect to your WiFi network.

Same process can be used to re-setup the device with new WiFi network or to change any of the configuration settings without internet connection and mobile apps.

MQTT Topics

Garadget subscribes for following topics:

/garadget/{device-name}/command

Acceptable payloads:

  • open - to open the door
  • close - to close the door
  • stop - to stop the door if in motion
  • get-config - to request the config update posted to config topic (see below)
  • get-status - to request the status update posted to status topic (see below)

/garadget/{device-name}/config

Acceptable payload is JSON with any combination of following properties:

  {"rdt":num,"mtt":num,"rlt":num,"rlp":num,"srt":num,"nme":"str","mqtt":num,"":"str","mqpt":str,"mqus":"str","mqto":num}
  • rdt - sensor scan interval in mS (200-60,000, default 1,000)
  • mtt - door moving time in mS from completely opened to completely closed (1,000 - 120,000, default 10,000)
  • rlt - button press time mS, time for relay to keep contacts closed (10-2,000, default 300)
  • rlp - delay between consecutive button presses in mS (10-5,000 default 1,000)
  • srt - reflection threshold below which the door is considered open (1-80, default 25)
  • nme - device name to be used in MQTT topic. If cloud connection enabled, at reboot this value will be overwritten with the one saved in cloud via the apps
  • mqtt - bitmap 0x01 - cloud enabled, 0x02 - mqtt enabled, 0x03 - cloud and mqtt enabled
  • mqip - MQTT broker IP address
  • mqpt - MQTT broker port number
  • mqus - MQTT user
  • mqto - MQTT timeout (keep alive) in seconds

Garadget publishes to the following topics

/garadget/{device-name}/status

At the boot, reconnect, when status changed or when requested with the get-status command (see above). The payload is the JSON like this:

{"status":"str","time":"str","sensor":num,"bright":num,"signal":num}
  • status - status of the door (open/closed/stopped)
  • time - time in status (10s, 20m, 15h, 10d etc)
  • sensor - reflection rate (0-99)
  • bright - ambient light brightness (0-99)
  • signal - WiFi signal strength in dB e.g. -40

/garadget/{device-name}/config

At the boot, reconnect, when configuration changed or when requested with the get-config command (see above). The payload is the same as that of get-config command but with additional read-only properties:

  • sys - Particle system firmware version
  • ver - Garadget firmware version (1.19)
  • id - Garadget/Particle device ID
  • ssid - WiFi access point (network) name

Below is the Home Assistant configuration code that seems to work for me. I’m poking at it for only few days so anybody with experience is welcome to suggest improvements (icons, etc).

create cover in configuration.yaml

cover:
  - platform: mqtt
    name: "Garage Door"
    command_topic: "garadget/Home/command"
    state_topic: "garadget/Home/status"
    payload_open: "open"
    payload_close: "close"

in sensors.yaml linked from configuration.yaml with sensor: !include sensors.yaml

- platform: mqtt
  name: 'Garage Door'
  state_topic: 'garadget/Home/status'
  value_template: '{{ value_json.status }}'

- platform: mqtt
  name: 'Garage Brightness'
  state_topic: 'garadget/Home/status'
  unit_of_measurement: '%'
  value_template: '{{ value_json.bright }}'

in automations.yaml periodically request the status to keep the brightness updated

- alias: 'Update Garage Brightness'
  trigger:
    platform: time
    minutes: '/2'
    seconds: 00
  action:
    service: mqtt.publish
    data:
      topic: "garadget/Home/command"
      payload: "get-status"

Your feedback and suggestions are very welcome.


#6

A post was split to a new topic: MQTT firmware request