Hi all,
I hope someone can help me with this.
I have MQT setup as standard in HASS.IO and have the sonoff power switches working well.
I now have flashed the Sonoff bridge to allow me to use PIRs and Door/window switches.
The problem I have, is I’m unsure as to how to use the triggers from this device and get automation to work.
The MQT response is as follows:
18:50:49 MQT: tele/sonoffbridge/RESULT = {“RfReceived”:{“Sync”:12540,“Low”:420,“High”:1210,“Data”:“D1397E”,“RfKey”:“None”}}
Any idea how I develop an automation from this data?
many thanks
Andy.
myle
(StePhan McKillen (Other kiwi Here))
February 20, 2018, 10:28am
2
try this Link
will try to explan
as the MQTT is a Json Message
02:16:38 MQT: tele/sonoff_pow_1/SENSOR = {“Time”:“2018-01-25T02:16:38”,“ENERGY”:{“Total”:0.149,“Yesterday”:0.079,“Today”:0.070,“Period”:0,“Power”:22,“Factor”:0.52,“Voltage”:228,“Current”:0.183}}
think of each { as start of a object and the next { is the child of it
so want to read the
MQTT of the tele/sonoff_pow_1/SENSOR
state_topic: "tele/sonoff_pow_1/SENSOR"
as we want to Read the Yesterday value which is in side the ENERGY { } which is …
as is a JSON Object
this should work
base on my understanding of JSON
- platform: mqtt
name: RfReceived
state_topic: "tele/sonoffbridge/RESULT"
value_template: "{{value_json.Data }}"
Put it into a Group
then RfReceived should show D1397E
once that Done
you should be able to create a Automation base on the RfReceived
this is base on my understanding of HA never tryed to read a single JSON Data Array
1 Like
cardblower:
tele/sonoffbridge/RESULT
Many thanks for the reply, much appreciated.
I’ve used the following in my configuration.yaml:
sensor:
platform: mqtt
name: “sonoffPIR1”
state_topic: “tele/sonoffbridge/RESULT”
value_template: ‘{{ value_json[“RfReceived”][“Data”] }}’
expire_after: 3
This now shows as a sensor in the top of the HASS.IO home page, and triggers from one of my automation rules.
Great help!! Thank you!!
1 Like
myle
(StePhan McKillen (Other kiwi Here))
February 20, 2018, 8:50pm
4
nice glad i could help
lets see your automation what have you got it doing
mite give someone else some ideas
what does the “expire_after: 3” do ???
Hi,
I’m using the PIR to notify me of visitors when I’m in the study and can’t hear the doorbell.
The automation is:
Trigger type: STATE
Entity: sensor.sonoffpir1
From:
To: D1397E
This fires a colourful led strip to let me know someone is at the door.
The “expire_after: 3” simply clears the PIR State back to blank after 3 seconds (as there is no trigger from the MQTT to clear it).
I then use another automation to turn off the LEDs based on the expire.
I could have used timers, but this is so much simpler
thanks again, without your help I wouldn’t have got this far.
regards
Andy
MRO
February 24, 2018, 1:32am
6
Hi Cardblower, I’m working on this topic for 2 days now and I don’t get this to work.
I used you code:
sensor:
platform: mqtt
name: “sonoffPIR1”
command_topic: “tele/sonoffbridge/RESULT”
value_template: ‘{{ value_json[“RfReceived”][“Data”] }}’
expire_after: 20
But when I restart HA I get the following:
Failed config
sensor.mqtt:
platform: mqtt
command_topic: tele/sonoffbridge/RESULT
expire_after: 20
name: sonoffPIR1
value_template: {{ value_json[“RfReceived”][“Data”] }}
Successful config (partial)
sensor.mqtt:
I think I do something wrong :S Can you see whats the problem?
How have you setup the sonoff bridge mqtt settings?
Here’s mine:
cariboo
February 24, 2018, 8:34am
8
Check the quote marks, when I copied the value_template line I got some weird quote marks.
[“Data"]
as you can see the qoute marks at the start are different from the quote marks at the end, replacing all the qoute marks made the command work as it should.
MRO
February 24, 2018, 9:33am
9
I copied it exactly the same! But it fixed now There was something wrong in my code with the quote marks
MRO
February 24, 2018, 9:34am
10
That did the trick. Thanks!
cool, great that it’s all working!
1 Like