[SOLVED] Break up string into sections

I have a button which returns this MQTT string.

What code do i need to do to convert this

{"StatusNET":{"Hostname":"FrontDownlightsSonoff-6404","IPAddress":"192.168.0.124","Gateway":"192.168.0.1","Subnetmask":"255.255.255.0","DNSServer":"192.168.0.1","Mac":"5C:CF:7F:7A:59:04","Webserver":2,"WifiConfig":3}}

to just give me the ip address section?

You need to use the JSONPATH transform
Can you post your item definition, please?

I have been able to get this as a string

"IPAddress":"192.168.0.124"

using this code


rule "ip address Downlights"
when
	Item FrontDownlight_IP received command
then
	val IPStringdownlights = FrontDownlight_IP.state.toString.split(",")
	FrontDownlight_IP_String.postUpdate(IPStringdownlights.get(1))
end

This is my items file

String FrontDownlight_IP 	"Get Info"  										{ mqtt="<[broker:stat/FrontDownlightsSonoff/STATUS5:state:default],>[broker:cmnd/FrontDownlightsSonoff/STATUS:command:*:5]" }
String FrontDownlight_IP_String "Info [%s]"	 									

and this is what i get as a string return

{"StatusNET":{"Hostname":"FrontDownlightsSonoff-6404","IPAddress":"192.168.0.124","Gateway":"192.168.0.1","Subnetmask":"255.255.255.0","DNSServer":"192.168.0.1","Mac":"5C:CF:7F:7A:59:04","Webserver":2,"WifiConfig":3}}

I literally just want the IP address as Text.

OK, there is a way to get this directly from the mqtt binding with the JSONPATH transform
It is a very powerful tool to extract values from json strings
See:

http://goessner.net/articles/JsonPath/

String FrontDownlight_IP 	"Get Info"  										{ mqtt="<[broker:stat/FrontDownlightsSonoff/STATUS5:state:JSONPATH($.StatusNET.IPAddress)],>[broker:cmnd/FrontDownlightsSonoff/STATUS:command:*:5]" }
1 Like

Thanks heaps for that.

Just reading up on the sonoff devices. you can actually send IPAddress1 as a command and it responds with just that string. which works great.
Still you helped me though marked as complete

What firmware are you using i sonoff? Curiosity question.

Whatever the latest is, they were only uploaded within the last week.