Processing json data

Hi
My Actron air conditioner web interface produce following json result and what would be the best way to translate these information by getting the data by the web interface every 15min and show it under :climate panel or something similar within home assistent.

{ "G" : "0" , "V" :2, "D" :6, "DA" :{ "isOn" : false , "mode" :2, "fanSpeed" :2, "setPoint" :21.0, "roomTemp_oC" :26.0, "isInESP_Mode" : false , "fanIsCont" :0, "compressorActivity" :2, "errorCode" : "" , "individualZoneTemperatures_oC" :[ null , null , null , null , null , null , null , null ], "enabledZones" :[1,0,0,0,0,0,0,0], "liveTimer" : null }}

Status of the air conditioner "isOn" : false
Current temp : “roomTemp_oC” :26.0
Set temp : “setPoint” :21.0

After googling, would this be a good solution to get the data?

sensor:

  • platform: rest
    resource: http://localhost/6.json
    name: Temperature
    value_template: ‘{{ value_json.roomTemp_oC }}’
    unit_of_measurement: “°C”
    scan_interval: 900

Now how do I transfer the rest data to climet?

I don’t know about the “climate panel”, but to get the data into sensors you’re close. I think this might work better for you:

sensor:
  - platform: rest
    resource: http://localhost/6.json
    name: Temperature
    value_template: "{{ value_json.DA.roomTemp_oC }}"
    unit_of_measurement: "°C"
    scan_interval:
      minutes: 15
    json_attributes:
      - DA
  - platform: template
    sensors:
      ac_status:
        friendly_name: AC status
        value_template: "{{ state_attr('sensor.temperature', 'DA').isOn }}"
      ac_set_point:
        friendly_name: AC set-point
        value_template: "{{ state_attr('sensor.temperature', 'DA').setPoint }}"
        unit_of_measurement: "°C"

Hi,
thanks for the help,
but if I’m getting a json response as follows,

{“isOn”:false,“mode”:0,“fanSpeed”:1,“setPoint”:19.0,“roomTemp_oC”:18.4,“isInESP_Mode”:true,“fanIsCont”:0,“compressorActivity”:2,“errorCode”:"",“individualZoneTemperatures_oC”:[null,null,null,null,null,null,null,null],“enabledZones”:[0,0,0,0,0,0,0,0],“liveTimer”:null}

how do I set the ac status, since I can’t use the json attribute DA?

I have try follow but no luck
sensor:

  • platform: rest
    resource: http://localhost/6.json
    name: Temperature
    value_template: “{{ value_json.roomTemp_oC }}”
    unit_of_measurement: “°C”
    scan_interval:
    minutes: 15
  • platform: template
    sensors:
    ac_status:
    friendly_name: AC status
    value_template: “{{ state_attr(‘sensor.Temperature’).isOn }}”
    ac_set_point:
    friendly_name: AC set-point
    value_template: “{{ state_attr(‘sensor.Temperature’).setPoint }}”
    unit_of_measurement: “°C”

So that’s different than what you originally posted. If that’s the JSON response, then you can do:

sensor:
  - platform: rest
    resource: http://localhost/6.json
    name: Temperature
    value_template: "{{ value_json.roomTemp_oC }}"
    unit_of_measurement: "°C"
    scan_interval:
      minutes: 15
    json_attributes:
      - isOn
      - setPoint
  - platform: template
    sensors:
      ac_status:
        friendly_name: AC status
        value_template: "{{ state_attr('sensor.temperature', 'isOn') }}"
      ac_set_point:
        friendly_name: AC set-point
        value_template: "{{ state_attr('sensor.temperature', 'setPoint') }}"
        unit_of_measurement: "°C"

BTW, when you post YAML code, please follow the directions at the top of the page. Otherwise it’s difficult to read.

Just wondering if you got this to work @boomramada using this method? I’m trying to do the same but I can’t seem to get any results?

Can I ask what is your resource url? Mine looks something like this https://actron.ninja.is/rest/v0/device/ACONNECT001EC015ABFE_0_2_6?user_access_token=

I’ve been running this for about a year using individual python scripts for each task… an ugly method I know but it works.

I believe someone is also working on a component whom I am trying to get in touch with so it might all become a lot easier soon.

sensor:
  - platform: rest
    name: ACStatus
    json_attributes:
      - isOn
      - fanSpeed
      - setPoint
      - roomTemp
    resource: https://actron.ninja.is/rest/v0/device/ACONNECT001EC015ABFE_0_2_6?user_access_token=<accesstoken>
    value_template: '{{ value_json["data"]["last_data"]["DA"].isOn }}'
  - platform: template
    sensors:
      power:
        friendly_name: 'AC Status'
        value_template: "{{ state_attr('sensor.acstatus', 'isOn') }}"
      fan_speed:
        friendly_name: 'Fan Speed'
        value_template: "{{ state_attr('sensor.acstatus', 'fanSpeed') }}"
      set_temp:
        friendly_name: 'Set Temp'
        value_template: "{{ state_attr('sensor.acstatus', 'setPoint') }}"
      room_temp:
        friendly_name: 'Room Temp'
        value_template: "{{ state_attr('sensor.acstatus', 'roomTemp') }}"

Can anyone tell me if this is possible to parse multiple json attributes that aren’t in the direct “tree”? I’ve seen it done before and tested that it works when they are in the first line of the json results but can’t seem to get it to work or multiple attributes.

Is my only option to setup separate rest commands for each attribute? Is there a way I can reformat the URL so that it accesses the data I want as the first line?

Not exactly clear what you’re trying to do. It might help if you could provide a copy of what the returned JSON looks like, and what pieces of data you’re trying to retrieve from it.

Hi Phil, the json results look something like this.

The attributes i want to be able to access are all under the ‘DA’ string so to get there in HASSIO i have to go through [“data”][“last_data”][“DA”]. I can access the isOn attribute as per me config file above but i cant access any of the others.

Try this:

sensor:
  - platform: rest
    name: ACStatus
    json_attributes:
      - data
    resource: https://actron.ninja.is/rest/v0/device/ACONNECT001EC015ABFE_0_2_6?user_access_token=<accesstoken>
    value_template: '{{ value_json["data"]["last_data"]["DA"].isOn }}'
  - platform: template
    sensors:
      power:
        friendly_name: 'AC Status'
        value_template: "{{ state_attr('sensor.acstatus', 'data').last_data.DA.isOn }}"
      fan_speed:
        friendly_name: 'Fan Speed'
        value_template: "{{ state_attr('sensor.acstatus', 'data').last_data.DA.fanSpeed }}"
      set_temp:
        friendly_name: 'Set Temp'
        value_template: "{{ state_attr('sensor.acstatus', 'data').last_data.DA.setPoint }}"
      room_temp:
        friendly_name: 'Room Temp'
        value_template: "{{ state_attr('sensor.acstatus', 'data').last_data.DA.roomTemp }}"

Thanks for that. I’ll test it out when i get home from work this evening and report back :slight_smile:

Oops, just noticed a typo. I’ll go back and fix…

Sorry for late reply, but above not going to work.
Actron air work got two way system, you need to device status from the actual device (via local IP address) eg 192.168.x or so on. Then control are from rest call to third party site. eg. https://actron.ninja.is/rest/v0/device/

So this is what I got.

First you need a thermostat

climate:
- platform: generic_thermostat
name: Actron
ac_mode: true
target_sensor: sensor.temperature
heater: switch.actron_dummy

Then sensor

    sensor:
    - platform: rest
    resource: http://192.168.1.x/6.json
    name: Temperature
    value_template: "{{ value_json.roomTemp_oC }}"
    unit_of_measurement: "°C"
    json_attributes:
      - setPoint
      - isOn
    scan_interval:
      minutes: 2
    service: climate.set_temperature
    entity_id: climate.actron
    data_template:
        temperature: "{{ state_attr('sensor.temperature', 'setPoint') }}"
    - platform: template
    sensors:
      ac_status:
        friendly_name: AC status
        value_template: >-
          {% if states.sensor.temperature.attributes.isOn == true %}
            On
          {% else %}
            Off
          {% endif %}

Then you need a switch

- platform: rest
name: actron
resource: https://actron.ninja.is/rest/v0/device/
body_on: '{ "DA":{"amOn":true} }'
body_off: '{ "DA":{"amOn":false} }'
headers:
  Content-Type: application/json

I hope I format it correctly, this work except one issue, each time sensor get updated, it try to turn on the system. Eg. scan_intervel = 2 min, each time it try to turn on the unit. I wish there is a fix to that.

Idea is to scan the unit and update the status. That way if someone manually turn it on, HA will get updated. It would be good if someone can fix this, not to call the switch each time its update the status.

This is interesting because the URL that i use definitely gets me all the info i need as well as allowing me to send data back to the AC eg changing fan speed, modes, temps etc. You never used to be able to connect directly to the AC system, i know Actron have done work recently on the app and the servers so maybe theyve changed that and it’s definitely the way to go especially considering its all running locally and will be better to no expose my access token.

Will give both options a go tonight and see what i end up with. Thanks all.

That could be possible, device prob send those data to server, so same data available from the server. Either way, you still need to update the HA status even min or so in case someone manually turn on the system.

Yeah that’s right, it’s an annoying thing to do but I guess a good work around considering there’s no official api for the actron units.

I’ve currently got mine setup as individuals scripts like so…

Very manual but it works. I plan to clean it all up with the above info over the next few days.

Got this all working brilliantly thanks so much for your help guys :slight_smile:

I used a combination of both @boomramada and @pnbruckner methods after now understanding that I can use the AC’s local IP address so it all works great now.

1 Like

If you don’t mind can you show what scripts you got?

I plan to do a full write up in the next few days to show people exactly how to get all this working as I know there are a few people out there trying to get all this to work. Will tag you in that post once I finish writing it.

Ultimately, I’d love to get a component written for the Actron Connect system I just don’t have the coding experience.

Would be good to see an official solution for the ActronConnect. I’d really like to get the ActronConnect module, but no official API.

Hey guys, here’s some good news if you haven’t come across it yet.

2 Likes