Debugging json

Hi!

ha is driving me crazy. I’ve been trying to read the state from a rest url (json) the whole evening… over a command_line, command_state command.
My problem is, I don’t even know what data gets through to HA.
Is there a way to see what results arrive in ha?

Have you tried the rest sensor? https://www.home-assistant.io/components/sensor.rest/

Setting the ogger level to debug for whatever component you are using usual reveals enough information

I think I had a look. But my problem is, I don’t even know whether HA even sees the data. there’s only a status url that gives back a json will a lot of data and I’m (currently) only interested in a single entry. And so far I was completely unable to get it to work. But I don’t know whether the problems is getting the data into HA, or the problem is a value_template or whatever. It’s really impossible to debug.

tnx, I had a look at it but didn’t see you can define logging on an object level.

I had a look now (for other data). 2 questions there:
a) if want to pull more than one value from a device. it only knows a status rest url. Do I really have to pull the same data 20 times from the device for 20 objects or can I somehow ‘save’ it in ha?

Then, one looks like:

now, car will contain a number 0-4. each number sould be replaced with a string (i.E 4= car connected)
I tried with {% if … %} but really can’t get it to work. I really hate yaml it drives me crazy…

Can you describe what the returned JSON looks like, and exactly what you’re trying to get out of it? I’d be happy to suggest how to get this to work, but I’d need some idea of what that data looks like.

BTW, have you tried using curl from the same machine that you’re running HA on? That would be very helpful. If you don’t know how to do that, it would be like this:

curl http://192.168.1.252/status

Hi!

Yes, curl works, I also tried getting the data with command_status and curl

output looks like this:
$ curl http://192.168.1.252/status

{“version”:“B”,“tme”:“0510181934”,“rbc”:“11”,“rbt”:“28449326”,“car”:“2”,“amp”:“16”,“err”:“0”,“ast”:“0”,“alw”:“1”,“stp”:“0”,“cbl”:“32”,“pha”:“63”,“tmp”:“28”,“dws”:“33128”,“dwo”:“0”,“adi”:“0”,“uby”:“0”,“eto”:“180”,“wst”:“3”,“nrg”:[229,231,234,2,44,0,0,0,0,0,0,7,7,3,1,30],“fwv”:“024.2”,“sse”:“001891”,“wss”:“Home Benissa”,“wke”:“**************”,“wen”:“1”,“cdi”:“0”,“tof”:“101”,“tds”:“1”,“lbr”:“40”,“aho”:“3”,“afi”:“7”,“ama”:“32”,“al1”:“13”,“al2”:“16”,“al3”:“28”,“al4”:“30”,“al5”:“32”,“cid”:“255”,“cch”:“65535”,“cfi”:“65280”,“lse”:“1”,“ust”:“1”,“wak”:“x”,“r1x”:“2”,“dto”:“0”,“nmo”:“0”,“sch”:“AAAAAAAAAAAAAAAA”,“sdp”:“0”,“eca”:“0”,“ecr”:“0”,“ecd”:“0”,“ec4”:“0”,“ec5”:“0”,“ec6”:“0”,“ec7”:“0”,“ec8”:“0”,“ec9”:“0”,“ec1”:“0”,“rca”:“x”,“rcr”:“”,“rcd”:“”,“rc4”:“”,“rc5”:“”,“rc6”:“”,“rc7”:“”,“rc8”:“”,“rc9”:“”,“rc1”:“”,“rna”:“”,“rnm”:“”,“rne”:“”,“rn4”:“”,“rn5”:“”,“rn6”:“”,“rn7”:“”,“rn8”:“”,“rn9”:“”,“rn1”:“”}

I try to get different data, I managed to get the data with a sensor type rest, but what I don’t know is how to reformat the data I got. (i.E 1= on etc. )
But on the switch, I’m not able to get the state of alw (0 or 1). I can set it, but not by posting a json or something but with an url (what I did: curl -s -S -X GET http://192.168.1.252/mqtt?payload=alw=1 >/dev/null) for on.

I’ve been playing with the json code you posted above and I kept getting errors on rendering it until I realized that the double-quote marks that you are using aren’t standard text marks. If your website actually returns that data like that then you will have to figure out how to convert it.

Here is the code I used in the template editor to test what you want to do and it worked:

{% set value_json = 
{"version":"B","tme":"0510181934","rbc":"11","rbt":"28449326","car":"2","amp":"16","err":"0","ast":"0","alw":"1","stp":"0","cbl":"32","pha":"63","tmp":"28","dws":"33128","dwo":"0","adi":"0","uby":"0","eto":"180","wst":"3","nrg":[229,231,234,2,44,0,0,0,0,0,0,7,7,3,1,30],"fwv":"024.2","sse":"001891","wss":"Home Benissa","wke":"**************","wen":"1","cdi":"0","tof":"101","tds":"1","lbr":"40","aho":"3","afi":"7","ama":"32","al1":"13","al2":"16","al3":"28","al4":"30","al5":"32","cid":"255","cch":"65535","cfi":"65280","lse":"1","ust":"1","wak":"x","r1x":"2","dto":"0","nmo":"0","sch":"AAAAAAAAAAAAAAAA","sdp":"0","eca":"0","ecr":"0","ecd":"0","ec4":"0","ec5":"0","ec6":"0","ec7":"0","ec8":"0","ec9":"0","ec1":"0","rca":"x","rcr":"","rcd":"","rc4":"","rc5":"","rc6":"","rc7":"","rc8":"","rc9":"","rc1":"","rna":"","rnm":"","rne":"","rn4":"","rn5":"","rn6":"","rn7":"","rn8":"","rn9":"","rn1":""}
%}
{% if value_json.car == '1' %}
  disconnected
{% elif value_json.car == '2'  %}
  connected
{% endif %}

Notice the difference between your double quote marks and mine.

And once you get that sorted out the just continue on with the if statements to return values you want based on the key value you select.

Thanks. Hm, no, those quotes must have been converted on the way somewhere. Should have used code tags, sorry.
It sort of workst now. It’s just difficult if you’re both coping with what HA can do, how YAML actually works and what the device you’re trying to control can do.
I still have no idea how to actually set values on the device. It’s not that important either, but it would be nice. Maybe it would be easier to write a whole plugin after all :wink:

If you are trying to send changes to the device you need to use the POST command not GET in your curl message. I don’t know if the device will actually accept changes like that tho.