Search

Bringing IoT Cricket into Home Assistant

Updated: May 24


Integrate IoT Cricket to Home Assistant

Foreword: it is our customer blog from Alan Barnett who kindly shares how easily developers can integrate IoT Cricket Wi-Fi module to Home Assistant. Alan uses a NEW Cricket's feature added to the latest Cricket, which allows developers to configure custom MQTT brokers. Things On Edge awarded Alan its own laurel leaf trophy.



Overview

Since Cricket IoT can connect to an external MQTT broker it is perfect for integration by those of us who use Home Assistant with MQTT. The hardware set up followed that described in the DIY: WiFi Smart Button to control HUE lights where a push to make momentary switch is connected between the BATT and WAKE_UP pins. After connecting the module up to the Wi-Fi as detailed elsewhere the first thing I wanted to see was the MQTT messages it would provide, so I headed over to the developer console and entered the details of my local MQTT broker. What is great to note here is that the module will connect direct to the local MQTT broker with no need to connect out to the cloud.

Setting up local MQTT

Configure MQTT broker in TOE Developer Portal

Once that was activated by pressing the small switch. I waited for the led to flash and confirmed all was well by clicking the refresh button on the developer console. Then I brought up a command line tool to view the messages from the MQTT broker and pressed the button to trigger wake and sure enough data appeared


mosquitto_sub  -h a.b.c.d -v -t "/MYSERIAL/#"  -u cricket1 -P mypass

/MYSERIAL/io1_wake_up 1
/MYSERIAL/rtc_wake_up 0
/MYSERIAL/temp 23.6
/MYSERIAL/batt 237
/MYSERIAL/cnt_wake_up 47
/MYSERIAL/cnt_published 46



Creating Sensors

Since the battery and temperature info is delivered on the MQTT payload it is a simple task to create a couple of sensors within Home Assistant. The sensors I created look like this


And were defined as mqtt sensors as follows


- platform: mqtt
  name: cricket_temperature
  state_topic: "/MYSERIAL/temp"
  unit_of_measurement: '°C'
  device_class: temperature

- platform: mqtt
  name: cricket_battery
  state_topic: "/MYSERIAL/batt"
  value_template: "{{ value |  multiply(1000/255) | int/10 | float }}"
  unit_of_measurement: '%'
  device_class: battery
  

The battery sensor value is the current battery voltage level represented as a percentage to one decimal point. You could easily change this to show voltage using the method discussed in the developer guide making sure to account for the divider value.

Setting up a Toggle Switch

Next I wanted to use the WAKE_UP Switch to toggle an entity within Home Assistant so I created an input_boolean to record the state and an automation to change that state.



input_boolean:
  cricket1:
    name: Cricket IoT Switch

automation:
  - alias: cricket trigger virtual switch
    initial_state: 'on'
    trigger:
      - platform: mqtt
        topic: "/MYSERIAL/io1_wake_up"
        payload: "1"
    action:
      - service: input_boolean.toggle
        entity_id: input_boolean.cricket1


Now pressing the switch toggles the switch and the possibilities become endless.



-----------

This blog is posted on behalf of Alan Barnett. Big thank you from Things On Edge team!


0 views
logo.png

Registered in United Kingdom No. 11445097

Things On Edge Ltd

Cambridge, UK

CB25 9LT

Copyright © 2018 Things On Edge Limited

All rights reserved

  • LinkedIn - White Circle
  • White Facebook Icon
  • White Twitter Icon
  • White YouTube Icon