Robert Cudmore    archive    tags    search    software

Home Debian server setup

Tweaking MQTT server to talk to Homeassistant


Web interface is at:

For setup, see:

Application is in /srv/homeassistant/

Added a user /home/homeassistant

Main configuration file is: /home/homeassistant/.homeassistant/configuration.yaml

To edit configuration.yaml, switch user: sudo su -s /bin/bash homeassistant

To run homeassistant (from my normal account): sudo -u homeassistant -H /srv/homeassistant/bin/hass

todo: learn how to run this crap at startup

My homeassistant is subscribing and getting packets from mosquitto mqtt server with the following in configuration.yml

  #username: your_username
  #password: your_password

sensor 1:
  platform: mqtt
  name: "Temperature"
  state_topic: "nodemcu1/temperature"
  qos: 0
  unit_of_measurement: "ºC"

sensor 2:
  platform: mqtt
  name: "Humidity"
  state_topic: "nodemcu1/humidity"
  qos: 0
  unit_of_measurement: "%"

sensor 3:
  platform: mqtt
  name: "Light"
  state_topic: "nodemcu1/light"
  qos: 0
  unit_of_measurement: "%"

Python3 is in env py36

To get homeassistant working, installed virtual env ‘py36’ for python 3.6 install


conda create -n py36 python=3.6 anaconda

Activate environment

source activate py36

Deactivate environment

source deactivate


See MQTT post on how to start/stop


sudo systemctl start mosquitto
sudo systemctl stop mosquitto

MQTT is running at

Mosquitto config is in: /etc/mosquitto/mosquitto.conf

My node mcu is

Node MCU temperature sensor

This info is directly from router

temperature server

is in: ~/Sites/temperatureserver/

run it manually with screen (too much of a pain to get it to run on boot)

once running, is at: or:

Remember, duckdns only works because I (1) port forward to .200 on router and (2) run some sort of synch software (from duckdns people) to notify their servers when my dynamic IP changes

temperature server subscribes to the MQTT server and listens on broker channel ‘#’

paho.Client().subscribe('#', 0)

These are my mqtt broker channels

if msg.topic == 'nodemcu1/light':
	nodemcu1_light = str(msg.payload)
	#print '    nodemcu1_light=', nodemcu1_light
if msg.topic == 'nodemcu1/temperature':
	nodemcu1_temperature = str(msg.payload)
	#print '    nodemcu1_temperature=', nodemcu1_temperature
if msg.topic == 'nodemcu1/humidity':
	nodemcu1_humidity = str(msg.payload)
	#print '    nodemcu1_humidity=', nodemcu1_humidity

if msg.topic == 'nodemcu2/temperature':
	nodemcu2_temperature = str(msg.payload)
if msg.topic == 'nodemcu2/humidity':
	nodemcu2_humidity = str(msg.payload)
Tags: debian

©2017. Robert Cudmore.