I am a totally noob to most of this, and has been playing around with HA for 2-3 months now. I have tried to do it like in the link, but I must have done something wrong some place. Can I create a motion-sensor entity with the information provided above, or do I need some other info?
Maybe someone is willing to help me with my first sensor?
# Example configuration.yaml entry
mqtt:
binary_sensor:
- name: PIR Test
state_topic: "mqtt/out/EV1527_000373_0a"
payload_on: "on"
And I have tried to modify it to make it show as a motion
mqtt:
binary_sensor:
- name: PIR Test
state_topic: "mqtt/out/EV1527_000373_0a"
device_class: motion
payload_on: "on"
off_delay: 5
No mater what I do it shows up in entities, but does not react to motion ( wrong code somewhere )
Also tried to write it inside binary-sensor with mqtt platform like this:
Hi
not really sure if this is correct, don’t have much experience with templates, only did JSON-Data so far, but your data seems to be just a semicolon separated string
mqtt:
binary_sensor:
- name: PIR Test
state_topic: "mqtt/out"
payload_on: "ON"
value_template: >-
{% set list1 = value.split(';') %}
{% set cmd = list1[5].split("=") %}
{{cmd[1]}}
the value-template splits the data at the semicolon, takes the 6th (list starts at 0) element in the list and splits at the “=”-sign
works for me in the DEV-Tools, but I’m not sure if the value in the state topic is contained in variable “value”
When you configure an MQTT Binary Sensor properly, it will appear as a new binary_sensor in Developer Tools > States and in Configuration > Devices & Services > Entities. It won’t appear as a new topic in your MQTT Broker.
Are you seeing an entity named binary_sensor.pir_test in Developer Tools > States?
If you don’t see it in the list, execute Developer Tools > YAML > Reload Manually Configured MQTT Entities (or restart Home Assistant).
If you do see it in the list, what is its state value?
The fact that binary_sensor.pir_test reports unknown means that it has not yet received any payload via its state_topic. Are you sure Home Assistant is logged in and communicating with your MQTT broker?
Go to Configuration> Integrations > Mosquitto broker and click Configuration. You will be presented with a screen like shown below. Enter mqtt/out as shown in the screenshot and click Start Listening. It should display the payloads published to mqtt/out.
Changed it to mqtt/out and now it working. Thanx alot guys.
On to the next ( simple ) question: Can I add more than one value to the value template? Since I have alot of these sensors I need to separate them. So instead of the CMD=ON I would like to use both the ID and the switch.
value_template: "{{ 'ON' if 'BOTH ID AND SWITCH HERE' in value else 'OFF' }}"
Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic is resolved. This helps other users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.
If you have one topic, mqtt/out, that contains information from multiple devices then it’s best to use Strategy #2 in the following post:
In a nutshell, you create an automation that subscribes to mqtt/out (using an MQTT Trigger) and it examines the received payload. If the payload is from device A (represented by some combination of ID and SWITCH values), the automation publishes it to a different MQTT topic dedicated for the use of device A only. It’s a proven technique that simplifies the process of configuring MQTT entities that share a common MQTT topic.
I can help you implement this method but I would need to know the ID and SWITCH values for each device that publishes information to mqtt/out.