The last step is to tell Home Assistant how to interact with our new MQTT devices. Even though we only used one microcontroller, the HUZZAH Feather, the MQTT feeds will allow us to separate out control over all of our devices and sensors. Thankfully Home Assistant has an extensive lineup of different device types formatted for MQTT. There is one for an MQTT Lock, MQTT Binary Sensor, and even a special one for MQTT RGB Lights. Templates exist for all of these and unless you changed any of the Arduino code in the HuzzahCrickitIOT.ino file relating to the Feed names, you can just use the code below.
You will want to copy the following code and use it to replace all of the code in the configuration.yaml file using the Home Assistant Configurator tool.
# Configure a default setup of Home Assistant (frontend, api, etc) default_config: # Uncomment this if you are using SSL/TLS, running in Docker container, etc. # http: # base_url: example.duckdns.org:8123 # Text to speech tts: - platform: google_translate sensor: # Weather prediction - platform: yr - platform: mqtt name: "Light Sensor" state_topic: "house/lux" unit_of_measurement: 'Lux' icon: mdi:brightness-6 - platform: mqtt name: "Door Sensor" state_topic: "house/door" icon: mdi:door - platform: mqtt name: "Motion Sensor" state_topic: "house/motion" icon: mdi:motion-sensor fan: - platform: mqtt name: "Fan" state_topic: "house/fan" command_topic: "house/fan" speed_state_topic: "house/fan/speed" speed_command_topic: "house/fan/speed" qos: 0 payload_on: "ON" payload_off: "OFF" payload_low_speed: "low" payload_medium_speed: "medium" payload_high_speed: "high" speeds: - low - medium - high light: - platform: group name: All Lights entities: - light.light_1 - light.light_2 - light.light_3 - light.light_4 - light.light_5 - platform: mqtt name: "Light 1" state_topic: "house/led/one" command_topic: "house/led/one" brightness_state_topic: "house/led/one/brightness" brightness_command_topic: "house/led/one/brightness" rgb_state_topic: "house/led/one/color" rgb_command_topic: "house/led/one/color" on_command_type: first state_value_template: "{{ value_json.state }}" brightness_value_template: "{{ value_json.brightness }}" rgb_value_template: "{{ value_json.rgb | join(',') }}" qos: 0 payload_on: "ON" payload_off: "OFF" optimistic: false - platform: mqtt name: "Light 2" state_topic: "house/led/two" command_topic: "house/led/two" brightness_state_topic: "house/led/two/brightness" brightness_command_topic: "house/led/two/brightness" rgb_state_topic: "house/led/two/color" rgb_command_topic: "house/led/two/color" on_command_type: first state_value_template: "{{ value_json.state }}" brightness_value_template: "{{ value_json.brightness }}" rgb_value_template: "{{ value_json.rgb | join(',') }}" qos: 0 payload_on: "ON" payload_off: "OFF" optimistic: false - platform: mqtt name: "Light 3" state_topic: "house/led/three" command_topic: "house/led/three" brightness_state_topic: "house/led/three/brightness" brightness_command_topic: "house/led/three/brightness" rgb_state_topic: "house/led/three/color" rgb_command_topic: "house/led/three/color" on_command_type: first state_value_template: "{{ value_json.state }}" brightness_value_template: "{{ value_json.brightness }}" rgb_value_template: "{{ value_json.rgb | join(',') }}" qos: 0 payload_on: "ON" payload_off: "OFF" optimistic: false - platform: mqtt name: "Light 4" state_topic: "house/led/four" command_topic: "house/led/four" brightness_state_topic: "house/led/four/brightness" brightness_command_topic: "house/led/four/brightness" rgb_state_topic: "house/led/four/color" rgb_command_topic: "house/led/four/color" on_command_type: first state_value_template: "{{ value_json.state }}" brightness_value_template: "{{ value_json.brightness }}" rgb_value_template: "{{ value_json.rgb | join(',') }}" qos: 0 payload_on: "ON" payload_off: "OFF" optimistic: false - platform: mqtt name: "Light 5" state_topic: "house/led/five" command_topic: "house/led/five" brightness_state_topic: "house/led/five/brightness" brightness_command_topic: "house/led/five/brightness" rgb_state_topic: "house/led/five/color" rgb_command_topic: "house/led/five/color" on_command_type: first state_value_template: "{{ value_json.state }}" brightness_value_template: "{{ value_json.brightness }}" rgb_value_template: "{{ value_json.rgb | join(',') }}" qos: 0 payload_on: "ON" payload_off: "OFF" optimistic: false lock: - platform: mqtt name: Frontdoor state_topic: "house/lock" command_topic: "house/lock" payload_lock: "LOCK" payload_unlock: "UNLOCK" optimistic: true qos: 1 #retain: true value_template: '{{ value.x }}' group: !include groups.yaml automation: !include automations.yaml script: !include scripts.yaml
If there are no code errors, restart Home Assistant using the Server Control from the Configuration menu to update with these new devices.
Page last edited March 08, 2024
Text editor powered by tinymce.