Use partial JSON

Hi there,

I have a question. I have a RF doorbell, which signal is picked up by a Sonoff Bridge and sent via MQTT to Hass. That’s great. The MQTT message is the RF data in JSON, like this:
AA B1 05 0140 0A3C 00D2 04D8 2800 481828383828382828383828283828382838382838083828380808382838380838080838380838082838380808382838380838082838283838083808083838083828 55

The data is picked up by a sensor in HASS. The problem is that the code changes a bit and I want to use an automation only based on a part of the JSON code, is that possible? So only use the “481828383828382828383828283828382838382838083828380808382838380838080838380838082838380808382838380838082838283838083808083838083828” part

Thanks

If the output format is always the same, you can split and use the nth field.
Paste this in Dev tools/templates and play with it.

{% set string = 'AA B1 05 0140 0A3C 00D2 04D8 2800 481828383828382828383828283828382838382838083828380808382838380838080838380838082838380808382838380838082838283838083808083838083828 55' %}
{{ string.split()[8] }}

Great, that works. How do I implement that on the sensor?

  - platform: mqtt
    name: "Doorbell"
    state_topic: "tele/sonoffrf/RESULT"
    value_template: '{{ value_json["RfRaw"]["Data"] }}'
value_template: '{{ value_json["RfRaw"]["Data"].split()[8] }}'
1 Like

Great, I give it a try