CatMan
Published

Easy way to use the Unihiker K10 with Home-Assistant

The Unihiker K10 has sensors and built-in AI for simple voice/image recognition. Alone, it can't do much, but with Home Assistant... a LOT!

IntermediateFull instructions provided1 hour3
Easy way to use the Unihiker K10 with Home-Assistant

Things used in this project

Hardware components

DFRobot Unihiker K10
×1

Software apps and online services

Home Assistant
Home Assistant
DFRobot Mind+

Story

Read more

Code

K10_MQTT_LightsHAOSautomation.yaml

YAML
This is a Home Assistant Automation. It is triggered by specific MQTT messages and turns respective lights on and off.
alias: K10_MQTT_Lights
description: ""
triggers:
  - trigger: mqtt
    topic: UniK10/Lights
    id: TrigID0
    payload: BathOn
  - trigger: mqtt
    topic: UniK10/Lights
    payload: BathOff
    id: TrigID1
  - trigger: mqtt
    topic: UniK10/Lights
    id: TrigID2
    payload: BedrOn
  - trigger: mqtt
    topic: UniK10/Lights
    id: TrigID3
    payload: BedrOff
  - trigger: mqtt
    topic: UniK10/Lights
    id: TrigID4
    payload: ChinaLights
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - TrigID0
        sequence:
          - action: automation.trigger
            metadata: {}
            data:
              skip_condition: true
            target:
              entity_id: automation.cat_bath_on_hue_1_on_short
      - conditions:
          - condition: trigger
            id:
              - TrigID1
        sequence:
          - action: light.turn_off
            metadata: {}
            data: {}
            target:
              area_id: cat_bathroom
      - conditions:
          - condition: trigger
            id:
              - TrigID2
        sequence:
          - action: automation.trigger
            metadata: {}
            data:
              skip_condition: true
            target:
              entity_id: automation.cat_bed_on_hue_2_short_based_on_time
      - conditions:
          - condition: trigger
            id:
              - TrigID3
        sequence:
          - action: light.turn_off
            metadata: {}
            data: {}
            target:
              device_id: d8e91ec1298e9a8114723d9e65304128
      - conditions:
          - condition: trigger
            id:
              - TrigID4
        sequence:
          - action: scene.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: scene.cat_bedroom_chinatown
mode: single

MQTT_HA_VoiceLights.ino

Arduino
This was auto-generated by the Mind+ IDE. You can paste it in the "Manual Editing" tab or generate the corresponding blocks code. It recognizes specific voice commands and sends MQTT messages to HA.
/*!
 * MindPlus
 * esp32s3bit
 *
 */
#include "asr.h"
#include <DFRobot_Iot.h>
#include "unihiker_k10.h"

// Static constants
const String topics[5] = {"UniK10/AutoBdrOn","","","",""};
// Create an object
UNIHIKER_K10 k10;
ASR          asr;
DFRobot_Iot  myIot;
uint8_t      screen_dir=2;


// Main program start
void setup() {
	k10.begin();
	asr.asrInit(CONTINUOUS, EN_MODE, 3000);
	while(asr._asrState == 0){delay(100);}
	k10.initScreen(screen_dir);
	k10.creatCanvas();
	myIot.setCustomMqttCallback(obloqMqttEventTsiot47switch, "siot/switch");
	asr.addASRCommand(0+1, "bathroom light on");
	asr.addASRCommand(1+1, "bathroom light off");
	asr.addASRCommand(2+1, "bedroom light on");
	asr.addASRCommand(3+1, "bedroom light off");
	asr.addASRCommand(4+1, "Chinatown lights");
	myIot.wifiConnect("MySSID", "MyPwd");
	k10.canvas->canvasText("Connecting WiFi", 0, 0, 0x0000FF, k10.canvas->eCNAndENFont24, 50, true);
	k10.canvas->updateCanvas();
	while (!myIot.wifiStatus()) {}
	k10.canvas->canvasText(myIot.getWiFiLocalIP(), 0, 0, 0x0000FF, k10.canvas->eCNAndENFont24, 50, true);
	k10.canvas->updateCanvas();
	myIot.init("192.168.0.xx","mqttuserName","SomeGeneratedNumber","mqttPassword", topics, 1883);
	myIot.connect();
	k10.canvas->canvasText("Connecting MQTT", 0, 30, 0x0000FF, k10.canvas->eCNAndENFont24, 50, true);
	k10.canvas->updateCanvas();
	while (!myIot.connected()) {}
	k10.canvas->canvasText("MQTT Connected", 0, 30, 0x0000FF, k10.canvas->eCNAndENFont24, 50, true);
	k10.canvas->updateCanvas();
}
void loop() {
	if (asr.isWakeUp()) {
		k10.canvas->canvasText("Say Command", 4, 0x0000FF);
		k10.canvas->updateCanvas();
	}
	else {
		k10.canvas->canvasText("Say \"Hi Telly\"", 4, 0x0000FF);
		k10.canvas->updateCanvas();
	}
	if (asr.isDetectCmdID(0+1)) {
		myIot.publish("UniK10/Lights", "BathOn");
	}
	else {
		if (asr.isDetectCmdID(1+1)) {
			myIot.publish("UniK10/Lights", "BathOff");
		}
		else {
			if (asr.isDetectCmdID(2+1)) {
				myIot.publish("UniK10/Lights", "BedrOn");
			}
			else {
				if (asr.isDetectCmdID(3+1)) {
					myIot.publish("UniK10/Lights", "BedrOff");
				}
				else {
					if (asr.isDetectCmdID(4+1)) {
						myIot.publish("UniK10/Lights", "ChinaLights");
					}
					else {
					}
				}
			}
		}
	}
}

Credits

CatMan
4 projects • 3 followers
Thanks to The DFRobot Team and .

Comments