Home Assistant: Difference between revisions

From Leo's Notes
This page was last edited on 15 July 2021, at 00:01.
No edit summary
Line 10: Line 10:
As a side note: For read-only switch sensors (eg. PIR/alarm zones), Tasmota should be configured with <code>SetOption114 1</code> and <code>SwitchOption# 15</code>. With this configuration, the switches should appear as a binary sensor.
As a side note: For read-only switch sensors (eg. PIR/alarm zones), Tasmota should be configured with <code>SetOption114 1</code> and <code>SwitchOption# 15</code>. With this configuration, the switches should appear as a binary sensor.


=== Changing a Tasmota switch as a motion device ===
===Changing a Tasmota switch as a motion device===
Tasmota switches with <code>SetOption114</code> are detected as binary_sensors by default. For blueprints that filter based on specific device classes (Eg. motion, light bulb), you will want change the device class. The simplest solution is to make your Tasmota device announce its configuration so that Home Assistant can auto-discover the configuration without requiring changes made to <code>configuration.yml</code>.
Tasmota switches with <code>SetOption114</code> are detected as binary_sensors by default. For blueprints that filter based on specific device classes (Eg. motion, light bulb), you will want change the device class. The simplest solution is to make your Tasmota device announce its configuration so that Home Assistant can auto-discover the configuration without requiring changes made to <code>configuration.yml</code>.


Line 34: Line 34:
The <code>state_topic</code> is dependent on the <code>FullTopic</code> value that's configured in Tasmota. My configuration has it set to <code>tasmota/%topic%/%prefix%/</code> which means <code>Switch5</code> will announce its state at <code>tasmota/%topic%/stat/STATE5</code>. You will need to adjust the <code>state_topic</code> and <code>availability_topic</code> depending on your configuration. The on/off payload is also the default values of "ON" and "OFF".  Set the <code>unique_id</code> to something unique for this PIR sensor -- this value will be used in Home Assistant.
The <code>state_topic</code> is dependent on the <code>FullTopic</code> value that's configured in Tasmota. My configuration has it set to <code>tasmota/%topic%/%prefix%/</code> which means <code>Switch5</code> will announce its state at <code>tasmota/%topic%/stat/STATE5</code>. You will need to adjust the <code>state_topic</code> and <code>availability_topic</code> depending on your configuration. The on/off payload is also the default values of "ON" and "OFF".  Set the <code>unique_id</code> to something unique for this PIR sensor -- this value will be used in Home Assistant.


Convert this Yaml into compressed JSON (use https://onlineyamltools.com/convert-yaml-to-json). Repeat this again for any additional PIR sensors that are connected to this Tasmota device.
Convert this Yaml into compressed JSON (use https://onlineyamltools.com/convert-yaml-to-json). You should have something that looks like this:
 
{{Highlight
| code = <nowiki>{"name":"Main Floor PIR","state_topic":"tasmota/%topic%/stat/STATE5","payload_on":"ON","payload_off":"OFF","availability_topic":"tasmota/%topic%/tele/LWT","payload_available":"Online","payload_not_available":"Offline","device_class":"motion","force_update":true,"unique_id":"%deviceid%_mainfloor_motion","device":{"identifiers":["%deviceid%"]}}</nowiki>
| lang = json
}}
 
Generate the Yaml and JSON configuration for any additional PIR sensors that are connected to this Tasmota device.


Create a new rule that announces the configuration when the Tasmota device boots by running the following command in the Tasmota console (or via MQTT). Additional PIRs can be appended to the backlog command.
Create a new rule that announces the configuration when the Tasmota device boots by running the following command in the Tasmota console (or via MQTT). Additional PIRs can be appended to the backlog command.

Revision as of 00:01, 15 July 2021

Home assistant is an open source home automation platform that can run on a local server. It makes it extremely easy to integrate data from online and sensors around your home and performing some action based on the input.

Tasks

Adding Tasmota devices to Home Assistant

For the most part, Tasmota devices should automatically be found once you add the MQTT integration followed by the Tasmota integration. There is nothing to configure with the Tasmota configuration, however your devices running Tasmota need to be configured with an appropriate Topic and FullTopic MQTT setting (the defaults should work!).

If your devices aren't being detected by Home Assistant, ensure that your Tasmota devices have FullTopic set to something that includes the %prefix% and %topic% variables. Eg. /tasmota/%topic%/%prefix%/. Restart the device. When the devices connects to the MQTT server, the Tasmota integration should be able to detect it.

As a side note: For read-only switch sensors (eg. PIR/alarm zones), Tasmota should be configured with SetOption114 1 and SwitchOption# 15. With this configuration, the switches should appear as a binary sensor.

Changing a Tasmota switch as a motion device

Tasmota switches with SetOption114 are detected as binary_sensors by default. For blueprints that filter based on specific device classes (Eg. motion, light bulb), you will want change the device class. The simplest solution is to make your Tasmota device announce its configuration so that Home Assistant can auto-discover the configuration without requiring changes made to configuration.yml.

In the example below, I will be changing two PIR motion detectors connected to switch5 and switch6 into a motion device class.

For the first PIR connected to switch5, we will write the following Yaml:

name: Main Floor PIR
state_topic: tasmota/%topic%/stat/STATE5
payload_on: "ON"
payload_off: "OFF"
availability_topic: tasmota/%topic%/tele/LWT
payload_available: Online
payload_not_available: Offline
device_class: motion
force_update: true
unique_id: '%deviceid%_mainfloor_motion'
device:
  identifiers:
    - '%deviceid%'

The state_topic is dependent on the FullTopic value that's configured in Tasmota. My configuration has it set to tasmota/%topic%/%prefix%/ which means Switch5 will announce its state at tasmota/%topic%/stat/STATE5. You will need to adjust the state_topic and availability_topic depending on your configuration. The on/off payload is also the default values of "ON" and "OFF". Set the unique_id to something unique for this PIR sensor -- this value will be used in Home Assistant.

Convert this Yaml into compressed JSON (use https://onlineyamltools.com/convert-yaml-to-json). You should have something that looks like this:

{"name":"Main Floor PIR","state_topic":"tasmota/%topic%/stat/STATE5","payload_on":"ON","payload_off":"OFF","availability_topic":"tasmota/%topic%/tele/LWT","payload_available":"Online","payload_not_available":"Offline","device_class":"motion","force_update":true,"unique_id":"%deviceid%_mainfloor_motion","device":{"identifiers":["%deviceid%"]}}

Generate the Yaml and JSON configuration for any additional PIR sensors that are connected to this Tasmota device.

Create a new rule that announces the configuration when the Tasmota device boots by running the following command in the Tasmota console (or via MQTT). Additional PIRs can be appended to the backlog command.

rule1 on system#boot do backlog publish2 <JSON1>; [publish2 <JSON2>;] endon

In my case where I had 2 PIRs, the rule1 command I used looked like this:

rule1 on system#boot do backlog publish2 homeassistant/binary_sensor/%deviceid%_mainfloor_motion/config {"name":"Main Floor PIR","state_topic":"tasmota/%topic%/stat/STATE5","payload_on":"ON","payload_off":"OFF","availability_topic":"tasmota/%topic%/tele/LWT","payload_available":"Online","payload_not_available":"Offline","device_class":"motion","force_update":true,"unique_id":"%deviceid%_mainfloor_motion","device":{"identifiers":["%deviceid%"]}}; publish2 homeassistant/binary_sensor/%deviceid%_basement_motion/config {"name":"Basement PIR","state_topic":"tasmota/%topic%/stat/STATE6","payload_on":"ON","payload_off":"OFF","availability_topic":"tasmota/%topic%/tele/LWT","payload_available":"Online","payload_not_available":"Offline","device_class":"motion","force_update":true,"unique_id":"%deviceid%_basement_motion","device":{"identifiers":["%deviceid%"]}} endon

Activate the rule, then reboot.

rule 1
restart 1

If everything worked, you should see the PIR sensors as motion devices in Home Assistant.

Setting up a reverse proxy to home assistant

In order for Home Assistant to work behind a reverse proxy, you will need to add the following to your configuration.yml file:

http:
  base_url: http://assistant.example.com
  use_x_forwarded_for: true
  trusted_proxies:
    - 127.0.0.1
    - 172.18.0.0/16

Adjust the reverse proxy subnet as required. In my case, because I was running Home Assistant behind a Traefik reverse proxy on the docker subnet, I allowed the entire 172.18.0.0/16 subnet, but you can be more precise.

Adding RTSP camera feeds to home assistant

The camera integration (https://www.home-assistant.io/integrations/camera/) can be activated by adding the following to your configuration.yml file.

camera:
  - platform: ffmpeg
    name: frontdoor
    input: -rtsp_transport tcp -i rtsp://rtsp-server/frontdoor

  - platform: ffmpeg
    name: street
    input: -rtsp_transport tcp -i rtsp://rtsp-server/street

After adding this, you should see the RTSP streams in your Lovelace dashboard.

Now that you've added a RTSP camera to Home Assistant, you can also configure it to record