We will need to make a second sensor to get the other messages but I think this should extract the adc into the state and all the attributes will be the same as they are now.
Again show the dev-tools state.
Also if you can give me the FULL JSON from the broker I can have a play with it here.
from this… the state is the full json. Then I can use the template editor to work it out. Like I said I always struggle with this shit extracting data but the template editor reveals all
ok so in the message, I see before/after every key. Why? How did you create this? They should just be normal quotes if they are a string. The whole format is also using invalid single quotes it seems (Or maybe copy/paste is causing that here). It should look like this:
{“rssi”:-37,“snr”:10,“pferror”:12272,“packetSize”:93,“message”:{“id”:“LoRaADC”,“name”:“Soil_1”,“model”:“LSMS092D”,“tempc”:21.93432,“hum”:46.93069,“adc”:879}}
Yeah they are screwing up the message data. those characters are what you usually inject to escape things in linux but they are screwing up the message string. You need to get rid of those to read the data in correctly… unless someone else has a different way
@Refuge When posting code (including MQTT messages) please surround it with backticks (key near Escape) or use the Preformatted text button in the editor.
At least one of your issues above is due to copying the “smart quotes” from a post into your code.
Look at the difference in quotes: “rssi” versus "rssi". The first one has been “enhanced” to use “66/99” quotes for easier reading by humans, but this totally screws up code.
Here’s what you need — paste into the template editor to see what’s going on. The variable a has the MQTT Explorer result you (correctly) pasted a few posts up.
{% set a = {"rssi":-37,"snr":10,"pferror":12272,"packetSize":93,"message":"{\"id\":\"LoRaADC\",\"name\":\"Soil_1\",\"model\":\"LSMS092D\",\"tempc\":21.93432,\"hum\":46.93069,\"adc\":879}"} %}
{{ a.rssi }} <-- gives -37
{{ a.message }} <-- gives a JSON-style string
{{ a.message|from_json }} <-- gives a data structure
{{ (a.message|from_json).id }} <-- gives LoRaADC