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