Configuration code

Some code will need to be added to the configuration.yaml file in Home Assistant. This will set up all the interactions with the sensors on the PyPortal. There are a few ways to do this, and if you are not familiar with Home Assistant, I recommend reading this guide on adding Configurator and then this one on editing the configuration.yaml file.

Add the following information onto your configuration.yaml file, but be sure to place each sensor type into their respective categories. This is most important if you already have devices listed under sensor, binary_sensor, or switch

Download: file
  - platform: mqtt
    name: "Temperature"
    state_topic: "pyportal/temperature"
    unit_of_measurement: '°C'
  - platform: mqtt
    name: "Light"
    state_topic: "pyportal/lux"
    unit_of_measurement: 'Lux'

  - platform: mqtt
    name: Movment
    state_topic: "pyportal/pir"
    payload_on: "1"
    payload_off: "0"
  - platform: mqtt
    name: Button2
    state_topic: "pyportal/button2"
    payload_on: "1"
    payload_off: "0"

  - platform: mqtt
    name: Button1
    command_topic: "pyportal/button1"
    state_topic: "pyportal/button1"
    payload_on: "1"
    payload_off: "0"
    state_on: "1"
    state_off: "0"

When you have checked your YAML code and saved, go to Server Control from the Configuration menu and click RESTART.

After a few seconds, you will see some text appear that will say Connection lost. Reconnecting... at the bottom left of the window. When that text disappears, the server is back online and your changes have been loaded.

This guide was first published on Jan 08, 2020. It was last updated on Jan 08, 2020.
This page (Configuration code) was last updated on Jul 07, 2020.