I'm using command_line & curl but there must be a better solution

I’m currently using curl to get data from app.melcloud.com that isn’t available in the MelCloud integration (see Mitsubishi MELCLOUD integration with Home Assistant - #502 by DJI). My solution is slow and inflexible: I’m sure HA provides better ways of getting this data. Should I be using Scrape, Multi-Scrape or something else? Can anyone help me get access to some of the many other devices available by issuing:

curl -H "X-MitsContextKey:MyContextKey" "https://app.melcloud.com/Mitsubishi.Wifi.Client/user/ListDevices?id=MyID&buildingID=MyBuildingID" | jq ".[].Structure.Devices[].Device"

At the moment I’m using the following in configuration.yaml:

  - platform: command_line
    name: HP_DHW_In
    command: curl -H "X-MitsContextKey:MyContextKey" "https://app.melcloud.com/Mitsubishi.Wifi.Client/user/ListDevices?id=ID&buildingID=bID" | jq ".[].Structure.Devices[].Device.DailyHotWaterEnergyConsumed"
    unit_of_measurement: kWh
    scan_interval: 86400
  - platform: command_line
    name: HP_DHW_Out
    command: curl -H "X-MitsContextKey:MyContextKey" "https://app.melcloud.com/Mitsubishi.Wifi.Client/user/ListDevices?id=ID&buildingID=bID" | jq ".[].Structure.Devices[].Device.DailyHotWaterEnergyProduced"
    unit_of_measurement: kWh
    scan_interval: 86400
  - platform: command_line
    name: HP_Htg_Out
    command: curl -H "X-MitsContextKey:MyContextKey" "https://app.melcloud.com/Mitsubishi.Wifi.Client/user/ListDevices?id=ID&buildingID=bID" | jq ".[].Structure.Devices[].Device.DailyHeatingEnergyProduced"
    unit_of_measurement: kWh
    scan_interval: 86400
  - platform: command_line
    name: HP_Htg_In
    command: curl -H "X-MitsContextKey:MyContextKey" "https://app.melcloud.com/Mitsubishi.Wifi.Client/user/ListDevices?id=ID&buildingID=bID" | jq ".[].Structure.Devices[].Device.DailyHeatingEnergyConsumed"
    unit_of_measurement: kWh
    scan_interval: 86400

Plus several other sensors using the same syntax.
I’m not sufficiently familiar with the languages used to see how to adapt my working curl command to the other platforms that get data into HA in a way that allows me to define icon, device_class etc. I’d be very grateful for some guidance please.

1 Like

Probably a rest sensor. Paste in what this gives please:

curl -H "X-MitsContextKey:MyContextKey" "https://app.melcloud.com/Mitsubishi.Wifi.Client/user/ListDevices?id=ID&buildingID=bID"

Hi, Thanks for looking at this. The curl responds with a lot of data:

[{"ID":395680,xxx,"District":1037,"FPDefined":true,"FPEnabled":false,"FPMinTemperature":10,"FPMaxTemperature":12,"HMDefined":true,"HMEnabled":true,"HMStartDate":"2023-01-02T17:31:00","HMEndDate":"2023-01-04T00:01:00","BuildingType":1,"PropertyType":8,"DateBuilt":"2022-04-01T00:00:00","HasGasSupply":false,"LocationLookupDate":"2022-05-15T09:02:26.443","Country":237,"TimeZoneContinent":3,"TimeZoneCity":43,"TimeZone":118,"Location":118437,"CoolingDisabled":false,"Expanded":true,"Structure":{"Floors":[],"Areas":[],"Devices":[{"DeviceID":40683548,"DeviceName":"Ithaca","BuildingID":395680,"BuildingName":null,"FloorID":null,"FloorName":null,"AreaID":null,"AreaName":null,"ImageID":183665,"InstallationDate":"2022-04-01T00:00:00","LastServiceDate":"2022-04-01T00:00:00","Presets":[],"OwnerID":509118,"OwnerName":null,"OwnerEmail":null,"AccessLevel":4,"DirectAccess":false,"EndDate":"2500-01-01T00:00:00","Zone1Name":null,"Zone2Name":null,"MinTemperature":0,"MaxTemperature":40,"HideVaneControls":false,"HideDryModeControl":false,"HideRoomTemperature":false,"HideSupplyTemperature":false,"HideOutdoorTemperature":false,"BuildingCountry":null,"OwnerCountry":null,"AdaptorType":3,"LinkedDevice":null,"Type":1,"MacAddress":"70:61:be:98:e7:f3","SerialNumber":"2155412070","Device":{"PCycleActual":0,"ErrorMessages":"","DeviceType":1,"FTCVersion":1500,"FTCRevision":"r0","LastFTCVersion":0,"LastFTCRevision":null,"FTCModel":3,"RefridgerentAddress":0,"DipSwitch1":78,"DipSwitch2":129,"DipSwitch3":16,"DipSwitch4":0,"DipSwitch5":2,"DipSwitch6":0,"HasThermostatZone1":true,"HasThermostatZone2":true,"TemperatureIncrement":0.5,"DefrostMode":0,"HeatPumpFrequency":0,"MaxSetTemperature":48.0,"MinSetTemperature":20.0,"RoomTemperatureZone1":21.0,"RoomTemperatureZone2":-39.0,"OutdoorTemperature":10.0,"FlowTemperature":27.5,"FlowTemperatureZone1":25.0,"FlowTemperatureZone2":25.0,"FlowTemperatureBoiler":25.0,"ReturnTemperature":27.5,"ReturnTemperatureZone1":25.0,"ReturnTemperatureZone2":25.0,"ReturnTemperatureBoiler":25.0,"BoilerStatus":false,"BoosterHeater1Status":false,"BoosterHeater2Status":false,"BoosterHeater2PlusStatus":false,"ImmersionHeaterStatus":false,"WaterPump1Status":true,"WaterPump2Status":true,"WaterPump3Status":false,"ValveStatus3Way":false,"ValveStatus2Way":true,"WaterPump4Status":false,"ValveStatus2Way2a":false,"ValveStatus2Way2b":false,"TankWaterTemperature":51.5,"UnitStatus":0,"HeatingFunctionEnabled":true,"ServerTimerEnabled":false,"ThermostatStatusZone1":false,"ThermostatStatusZone2":false,"ThermostatTypeZone1":0,"ThermostatTypeZone2":2,"MixingTankWaterTemperature":25.0,"CondensingTemperature":40.57,"DemandPercentage":90,"ConfiguredDemandPercentage":null,"HasDemandSideControl":true,"DailyHeatingEnergyConsumed":3.85,"DailyCoolingEnergyConsumed":0.0,"DailyHotWaterEnergyConsumed":1.87,"DailyHeatingEnergyProduced":12.84,"DailyCoolingEnergyProduced":0.0,"DailyHotWaterEnergyProduced":4.27,"DailyLegionellaActivationCounter":1,"LastLegionellaActivationTime":"2023-01-04T15:01:00Z","EffectiveFlags":0,"LastEffectiveFlags":0,"Power":true,"EcoHotWater":false,"OperationMode":2,"OperationModeZone1":2,"OperationModeZone2":1,"SetTemperatureZone1":22.0,"SetTemperatureZone2":22.0,"SetTankWaterTemperature":51.0,"TargetHCTemperatureZone1":26.5,"TargetHCTemperatureZone2":30.0,"ForcedHotWaterMode":false,"HolidayMode":false,"ProhibitHotWater":false,"ProhibitHeatingZone1":false,"ProhibitHeatingZone2":false,"ProhibitCoolingZone1":false,"ProhibitCoolingZone2":false,"ServerTimerDesired":false,"SecondaryZoneHeatCurve":false,"SetHeatFlowTemperatureZone1":30.0,"SetHeatFlowTemperatureZone2":30.0,"SetCoolFlowTemperatureZone1":20.0,"SetCoolFlowTemperatureZone2":20.0,"DECCReport":false,"CSVReport1min":false,"Zone2Master":false,"DailyEnergyConsumedDate":"2023-01-12T00:00:00","DailyEnergyProducedDate":"2023-01-12T00:00:00","CurrentEnergyConsumed":0,"CurrentEnergyProduced":0,"CurrentEnergyMode":null,"HeatingEnergyConsumedRate1":0,"HeatingEnergyConsumedRate2":0,"CoolingEnergyConsumedRate1":0,"CoolingEnergyConsumedRate2":0,"HotWaterEnergyConsumedRate1":0,"HotWaterEnergyConsumedRate2":0,"HeatingEnergyProducedRate1":0,"HeatingEnergyProducedRate2":0,"CoolingEnergyProducedRate1":0,"CoolingEnergyProducedRate2":0,"HotWaterEnergyProducedRate1":0,"HotWaterEnergyProducedRate2":0,"ErrorCode2Digit":0,"SpSubDivisionsToWrite":0,"SpSubDivisionsToRead":0,"SpState":0,"SpSubDivisionsWriteInProgress":0,"SpSubDivisionsReadInProgress":0,"InitialSettingsData":null,"InitialSettingsTimestamp":null,"SupportsHourlyEnergyReport":false,"HasZone2":false,"HasSimplifiedZone2":false,"CanHeat":true,"CanCool":false,"HasHotWaterTank":true,"CanSetTankTemperature":true,"CanSetEcoHotWater":true,"HasEnergyConsumedMeter":true,"HasEnergyProducedMeter":true,"CanMeasureEnergyProduced":false,"CanMeasureEnergyConsumed":false,"Zone1InRoomMode":false,"Zone2InRoomMode":false,"Zone1InHeatMode":true,"Zone2InHeatMode":true,"Zone1InCoolMode":false,"Zone2InCoolMode":false,"AllowDualRoomTemperature":false,"IsGeodan":false,"HasEcoCuteSettings":false,"HasFTC45Settings":true,"HasFTC6Settings":true,"CanEstimateEnergyUsage":true,"CanUseRoomTemperatureCooling":false,"IsFtcModelSupported":true,"MaxTankTemperature":60.0,"IdleZone1":false,"IdleZone2":true,"MinPcycle":1,"MaxPcycle":1,"MaxOutdoorUnits":255,"MaxIndoorUnits":255,"MaxTemperatureControlUnits":0,"ModelCode":"027a","DeviceID":40683548,"MacAddress":"70:61:be:98:e7:f3","SerialNumber":"2155412070","TimeZoneID":118,"DiagnosticMode":0,"DiagnosticEndDate":null,"ExpectedCommand":1,"Owner":509118,"DetectedCountry":null,"AdaptorType":3,"FirmwareDeployment":null,"FirmwareUpdateAborted":false,"LinkedDevice":null,"WifiSignalStrength":-24,"WifiAdapterStatus":"NORMAL","Position":"Unknown","PCycle":2,"PCycleConfigured":null,"RecordNumMax":1,"LastTimeStamp":"2023-01-13T12:05:00","ErrorCode":8000,"HasError":false,"LastReset":"2022-11-16T10:51:30.208","FlashWrites":9,"Scene":null,"TemperatureIncrementOverride":0,"SSLExpirationDate":"2037-12-31T00:00:00","SPTimeout":1,"Passcode":null,"ServerCommunicationDisabled":false,"ConsecutiveUploadErrors":0,"DoNotRespondAfter":null,"OwnerRoleAccessLevel":1,"OwnerCountry":237,"HideEnergyReport":false,"ExceptionHash":null,"ExceptionDate":null,"ExceptionCount":null,"Rate1StartTime":null,"Rate2StartTime":null,"ProtocolVersion":0,"UnitVersion":0,"FirmwareAppVersion":37000,"FirmwareWebVersion":0,"FirmwareWlanVersion":0,"EffectivePCycle":1,"MqttFlags":9,"HasErrorMessages":false,"Offline":false,"Units":[]},"DiagnosticMode":0,"DiagnosticEndDate":null,"Location":118437,"DetectedCountry":null,"Registrations":59,"LocalIPAddress":null,"TimeZone":118,"RegistReason":"STARTUP","ExpectedCommand":1,"RegistRetry":2,"DateCreated":"2022-05-11T09:25:36.362Z","FirmwareDeployment":null,"FirmwareUpdateAborted":false,"Permissions":{"CanSetForcedHotWater":true,"CanSetOperationMode":true,"CanSetPower":true,"CanSetTankWaterTemperature":true,"CanSetEcoHotWater":false,"CanSetFlowTemperature":true,"CanSetTemperatureIncrementOverride":true}}],"Clients":[]},"AccessLevel":4,"DirectAccess":true,"MinTemperature":0,"MaxTemperature":40,"Owner":null,"EndDate":"2500-01-01T00:00:00","iDateBuilt":null,"QuantizedCoordinates":{"Latitude":51.05,"Longitude":-4.2}}]

Here’s what you need for the first two — I’m sure you can figure out the rest but do shout if you get stuck:

rest:
  - resource: https://app.melcloud.com/Mitsubishi.Wifi.Client/user/ListDevices?id=ID&buildingID=bID
    scan_interval: 86400
    headers:
      X-MitsContextKey: MyContextKey

    sensor:
      - name: "HP_DHW_In"
        value_template: "{{ value_json[0]['Structure']['Devices'][0]['Device']['DailyHotWaterEnergyConsumed'] }}"
        unit_of_measurement: kWh
        device_class: energy
        unique_id: 1080898c-5344-4cf6-a840-cf1371e75833

      - name: "HP_DHW_Out"
        value_template: "{{ value_json[0]['Structure']['Devices'][0]['Device']['DailyHotWaterEnergyProduced'] }}"
        unit_of_measurement: kWh
        device_class: energy
        unique_id: 6aa70c04-f1ca-40d8-b296-ea019d37e38f

The unique_ids are random: I use https://www.uuidgenerator.net/

This method has the advantage of only hitting their server once and generating all the sensor values from it.

If you paste the JSON in here: https://codebeautify.org/jsonviewer , you can find the path for each value you want:

image

Alternatively, here’s your JSON (de-personalised!) for pasting into Developer Tools / Templates, so you can check on your sensor code before writing it into the sensor — see the last line for my check of your first sensor:

{% set value_json = [
  {
    "Structure": {
      "Floors": [],
      "Areas": [],
      "Devices": [
        {
          "InstallationDate": "2022-04-01T00:00:00",
          "LastServiceDate": "2022-04-01T00:00:00",
          "Presets": [],
          "AccessLevel": 4,
          "DirectAccess": false,
          "EndDate": "2500-01-01T00:00:00",
          "Zone1Name": null,
          "Zone2Name": null,
          "MinTemperature": 0,
          "MaxTemperature": 40,
          "HideVaneControls": false,
          "HideDryModeControl": false,
          "HideRoomTemperature": false,
          "HideSupplyTemperature": false,
          "HideOutdoorTemperature": false,
          "AdaptorType": 3,
          "LinkedDevice": null,
          "Type": 1,
          "Device": {
            "PCycleActual": 0,
            "ErrorMessages": "",
            "DeviceType": 1,
            "FTCVersion": 1500,
            "FTCRevision": "r0",
            "LastFTCVersion": 0,
            "LastFTCRevision": null,
            "FTCModel": 3,
            "RefridgerentAddress": 0,
            "DipSwitch1": 78,
            "DipSwitch2": 129,
            "DipSwitch3": 16,
            "DipSwitch4": 0,
            "DipSwitch5": 2,
            "DipSwitch6": 0,
            "HasThermostatZone1": true,
            "HasThermostatZone2": true,
            "TemperatureIncrement": 0.5,
            "DefrostMode": 0,
            "HeatPumpFrequency": 0,
            "MaxSetTemperature": 48,
            "MinSetTemperature": 20,
            "RoomTemperatureZone1": 21,
            "RoomTemperatureZone2": -39,
            "OutdoorTemperature": 10,
            "FlowTemperature": 27.5,
            "FlowTemperatureZone1": 25,
            "FlowTemperatureZone2": 25,
            "FlowTemperatureBoiler": 25,
            "ReturnTemperature": 27.5,
            "ReturnTemperatureZone1": 25,
            "ReturnTemperatureZone2": 25,
            "ReturnTemperatureBoiler": 25,
            "BoilerStatus": false,
            "BoosterHeater1Status": false,
            "BoosterHeater2Status": false,
            "BoosterHeater2PlusStatus": false,
            "ImmersionHeaterStatus": false,
            "WaterPump1Status": true,
            "WaterPump2Status": true,
            "WaterPump3Status": false,
            "ValveStatus3Way": false,
            "ValveStatus2Way": true,
            "WaterPump4Status": false,
            "ValveStatus2Way2a": false,
            "ValveStatus2Way2b": false,
            "TankWaterTemperature": 51.5,
            "UnitStatus": 0,
            "HeatingFunctionEnabled": true,
            "ServerTimerEnabled": false,
            "ThermostatStatusZone1": false,
            "ThermostatStatusZone2": false,
            "ThermostatTypeZone1": 0,
            "ThermostatTypeZone2": 2,
            "MixingTankWaterTemperature": 25,
            "CondensingTemperature": 40.57,
            "DemandPercentage": 90,
            "ConfiguredDemandPercentage": null,
            "HasDemandSideControl": true,
            "DailyHeatingEnergyConsumed": 3.85,
            "DailyCoolingEnergyConsumed": 0,
            "DailyHotWaterEnergyConsumed": 1.87,
            "DailyHeatingEnergyProduced": 12.84,
            "DailyCoolingEnergyProduced": 0,
            "DailyHotWaterEnergyProduced": 4.27,
            "DailyLegionellaActivationCounter": 1,
            "LastLegionellaActivationTime": "2023-01-04T15:01:00Z",
            "EffectiveFlags": 0,
            "LastEffectiveFlags": 0,
            "Power": true,
            "EcoHotWater": false,
            "OperationMode": 2,
            "OperationModeZone1": 2,
            "OperationModeZone2": 1,
            "SetTemperatureZone1": 22,
            "SetTemperatureZone2": 22,
            "SetTankWaterTemperature": 51,
            "TargetHCTemperatureZone1": 26.5,
            "TargetHCTemperatureZone2": 30,
            "ForcedHotWaterMode": false,
            "HolidayMode": false,
            "ProhibitHotWater": false,
            "ProhibitHeatingZone1": false,
            "ProhibitHeatingZone2": false,
            "ProhibitCoolingZone1": false,
            "ProhibitCoolingZone2": false,
            "ServerTimerDesired": false,
            "SecondaryZoneHeatCurve": false,
            "SetHeatFlowTemperatureZone1": 30,
            "SetHeatFlowTemperatureZone2": 30,
            "SetCoolFlowTemperatureZone1": 20,
            "SetCoolFlowTemperatureZone2": 20,
            "DECCReport": false,
            "CSVReport1min": false,
            "Zone2Master": false,
            "DailyEnergyConsumedDate": "2023-01-12T00:00:00",
            "DailyEnergyProducedDate": "2023-01-12T00:00:00",
            "CurrentEnergyConsumed": 0,
            "CurrentEnergyProduced": 0,
            "CurrentEnergyMode": null,
            "HeatingEnergyConsumedRate1": 0,
            "HeatingEnergyConsumedRate2": 0,
            "CoolingEnergyConsumedRate1": 0,
            "CoolingEnergyConsumedRate2": 0,
            "HotWaterEnergyConsumedRate1": 0,
            "HotWaterEnergyConsumedRate2": 0,
            "HeatingEnergyProducedRate1": 0,
            "HeatingEnergyProducedRate2": 0,
            "CoolingEnergyProducedRate1": 0,
            "CoolingEnergyProducedRate2": 0,
            "HotWaterEnergyProducedRate1": 0,
            "HotWaterEnergyProducedRate2": 0,
            "ErrorCode2Digit": 0,
            "SpSubDivisionsToWrite": 0,
            "SpSubDivisionsToRead": 0,
            "SpState": 0,
            "SpSubDivisionsWriteInProgress": 0,
            "SpSubDivisionsReadInProgress": 0,
            "InitialSettingsData": null,
            "InitialSettingsTimestamp": null,
            "SupportsHourlyEnergyReport": false,
            "HasZone2": false,
            "HasSimplifiedZone2": false,
            "CanHeat": true,
            "CanCool": false,
            "HasHotWaterTank": true,
            "CanSetTankTemperature": true,
            "CanSetEcoHotWater": true,
            "HasEnergyConsumedMeter": true,
            "HasEnergyProducedMeter": true,
            "CanMeasureEnergyProduced": false,
            "CanMeasureEnergyConsumed": false,
            "Zone1InRoomMode": false,
            "Zone2InRoomMode": false,
            "Zone1InHeatMode": true,
            "Zone2InHeatMode": true,
            "Zone1InCoolMode": false,
            "Zone2InCoolMode": false,
            "AllowDualRoomTemperature": false,
            "IsGeodan": false,
            "HasEcoCuteSettings": false,
            "HasFTC45Settings": true,
            "HasFTC6Settings": true,
            "CanEstimateEnergyUsage": true,
            "CanUseRoomTemperatureCooling": false,
            "IsFtcModelSupported": true,
            "MaxTankTemperature": 60,
            "IdleZone1": false,
            "IdleZone2": true,
            "MinPcycle": 1,
            "MaxPcycle": 1,
            "MaxOutdoorUnits": 255,
            "MaxIndoorUnits": 255,
            "MaxTemperatureControlUnits": 0,
            "ModelCode": "027a",
            "DeviceID": 40683548,
            "MacAddress": "70:61:be:98:e7:f3",
            "SerialNumber": "2155412070",
            "TimeZoneID": 118,
            "DiagnosticMode": 0,
            "DiagnosticEndDate": null,
            "ExpectedCommand": 1,
            "Owner": 509118,
            "DetectedCountry": null,
            "AdaptorType": 3,
            "FirmwareDeployment": null,
            "FirmwareUpdateAborted": false,
            "LinkedDevice": null,
            "WifiSignalStrength": -24,
            "WifiAdapterStatus": "NORMAL",
            "Position": "Unknown",
            "PCycle": 2,
            "PCycleConfigured": null,
            "RecordNumMax": 1,
            "LastTimeStamp": "2023-01-13T12:05:00",
            "ErrorCode": 8000,
            "HasError": false,
            "LastReset": "2022-11-16T10:51:30.208",
            "FlashWrites": 9,
            "Scene": null,
            "TemperatureIncrementOverride": 0,
            "SSLExpirationDate": "2037-12-31T00:00:00",
            "SPTimeout": 1,
            "Passcode": null,
            "ServerCommunicationDisabled": false,
            "ConsecutiveUploadErrors": 0,
            "DoNotRespondAfter": null,
            "OwnerRoleAccessLevel": 1,
            "OwnerCountry": 237,
            "HideEnergyReport": false,
            "ExceptionHash": null,
            "ExceptionDate": null,
            "ExceptionCount": null,
            "Rate1StartTime": null,
            "Rate2StartTime": null,
            "ProtocolVersion": 0,
            "UnitVersion": 0,
            "FirmwareAppVersion": 37000,
            "FirmwareWebVersion": 0,
            "FirmwareWlanVersion": 0,
            "EffectivePCycle": 1,
            "MqttFlags": 9,
            "HasErrorMessages": false,
            "Offline": false,
            "Units": []
          },
          "DiagnosticMode": 0,
          "DiagnosticEndDate": null,
          "Location": 118437,
          "DetectedCountry": null,
          "Registrations": 59,
          "LocalIPAddress": null,
          "TimeZone": 118,
          "RegistReason": "STARTUP",
          "ExpectedCommand": 1,
          "RegistRetry": 2,
          "DateCreated": "2022-05-11T09:25:36.362Z",
          "FirmwareDeployment": null,
          "FirmwareUpdateAborted": false,
          "Permissions": {
            "CanSetForcedHotWater": true,
            "CanSetOperationMode": true,
            "CanSetPower": true,
            "CanSetTankWaterTemperature": true,
            "CanSetEcoHotWater": false,
            "CanSetFlowTemperature": true,
            "CanSetTemperatureIncrementOverride": true
          }
        }
      ],
      "Clients": []
    },
    "AccessLevel": 4,
    "DirectAccess": true,
    "MinTemperature": 0,
    "MaxTemperature": 40,
    "Owner": null,
    "EndDate": "2500-01-01T00:00:00",
    "iDateBuilt": null,
  }
] %}

{{ value_json[0]['Structure']['Devices'][0]['Device']['DailyHotWaterEnergyConsumed'] }}
1 Like

Thanks Troon, I really appreciate your help and that does look much better. I’ve replaced my yaml with the above and the sensors are created correctly with those attributes but I’m getting “state: unknown” back. No errors being shown in the log.

[sensor.hp_dhw_out](http://192.168.0.87:8123/developer-tools/state#)

HP_DHW_Out unknown unit_of_measurement: kWh device_class: energy friendly_name: HP_DHW_Out

Note that I’ve corrected an error: should be value_json not value.json in the sensors.

See my prior post — I suspect you have included my first-version mistake!

Obviously, you’ll need to put the correct id and buildingID into the resource line, and I assume MyContextKey is a placeholder too…

1 Like

Thanks Troon, I did indeed use your pre-corrected yaml and it now works. I am indebted to you and if you are every tempted to sail past again, come & say “Hi” and share some coffee
Now I’ve got a working start I can try to get to the bottom of why the heat pump is using twice the power my data predicts…

1 Like

Where exactly do you add this? As a card in the home dashboard or a new sensor somehow? I added this to my configuration.yml:

# Polling for Melcloud data curl -H "X-MitsContextKey:MyContextKey" "https://app.melcloud.com/Mitsubishi.Wifi.Client/user/ListDevices?id=$rest:
  - resource: https://app.melcloud.com/Mitsubishi.Wifi.Client/user/ListDevices?id=ID&buildingID=bID
    scan_interval: 86400
    headers:
      X-MitsContextKey: KEY_FETCHED_FROM_DEV_TOOLS

    sensor:
      - name: "HP_DHW_In"
        value_template: "{{ value_json[0]['Structure']['Devices'][0]['Device']['DailyHotWaterEnergyConsumed'] }}"
        unit_of_measurement: kWh
        device_class: energy
        unique_id: 1080898c-5344-4cf6-a840-cf1371e75833

      - name: "HP_DHW_Out"
        value_template: "{{ value_json[0]['Structure']['Devices'][0]['Device']['DailyHotWaterEnergyProduced'] }}"
        unit_of_measurement: kWh
        device_class: energy
        unique_id: 6aa70c04-f1ca-40d8-b296-ea019d37e38f

And then I added a new entity card:

type: entities
entities:
  - entity: sensor.HP_DHW_In

But sadly it cannot find the entity.

When I run curl -H “X-MitsContextKey:MyContextKey” "https://app.melcloud.com/Mitsubishi.Wifi.Client/user/ListDevices?id=$rest: it does find my pump and shows me the data of the sensors.

Edit:
Aha now I solved it, turns out the correct sensor name was lower case!

type: entities
entities:
  - entity: sensor.hp_dhw_in

Hello all,
I have to intervene here.
I have read your posts and some others and tried, unfortunately I come to no success.

First of all for my understanding, the id, which is in front of the buildingID in the - resource path, is the id, of my heat pump (device), not the id of the floor or the area?
I ask so stupid, because my device id is 8 numbers long and not 5 like you.

The scan_interval, defines what exactly? The time how often it is requested from Melcloud?

Oh well, since I doubted myself, I just copied the last two sensors, but they also show nothing.
in the “Developer Tools” is neither unknown nor anything else.

Thanks a lot in advance.

Here is my config.yaml

rest:
  - resource: https://app.melcloud.com/Mitsubishi.Wifi.Client/user/ListDevices?id=11111111&buildingID=11111
    scan_interval: 60
    headers:
      X-MitsContextKey: MyCodeHere

    sensor:
      - name: "HeatPumpFrequency"
        value_template: "{{ value_json[0]['Structure']['Devices'][0]['Device']['HeatPumpFrequency'] }}"
        unit_of_measurement: Hz
        device_class: energy
        unique_id: 280220231

      - name: "DefrostMode"
        value_template: "{{ value_json[0]['Structure']['Devices'][0]['Device']['DefrostMode'] }}"
        unit_of_measurement: none
        device_class: energy
        unique_id: 280220232
        
      - name: "DailyHeatingEnergyConsumed"
        value_template: "{{ value_json[0]['Structure']['Devices'][0]['Device']['DailyHeatingEnergyConsumed'] }}"
        unit_of_measurement: kWh
        device_class: energy
        unique_id: 280220233

      - name: "HP_DHW_In"
        value_template: "{{ value_json[0]['Structure']['Devices'][0]['Device']['DailyHotWaterEnergyConsumed'] }}"
        unit_of_measurement: kWh
        device_class: energy
        unique_id: 1080898c-5344-4cf6-a840-cf1371e75833

      - name: "HP_DHW_Out"
        value_template: "{{ value_json[0]['Structure']['Devices'][0]['Device']['DailyHotWaterEnergyProduced'] }}"
        unit_of_measurement: kWh
        device_class: energy
        unique_id: 6aa70c04-f1ca-40d8-b296-ea019d37e38f

I did not need to specify the id. This worked for me:

https://app.melcloud.com/Mitsubishi.Wifi.Client/user/ListDevices?id=ID&buildingID=bID

But sadly the data is only updated once a day. So some of the fields are pretty worthless.

Hi,

Unfortunately, this does not work for me because I have more than one device, so I have to specify which one it is.

With the following command, I get an output in the terminal in Home Assistant, but unfortunately from all 6 devices.

I really don’t know what to do anymore :confused:

curl -v -H "X-MitsContextKey: MyKey" "https://app.melcloud.com/Mitsubishi.Wifi.Client/user/ListDevices?id=11111&buildingID=22222"| jq ".[].Structure.Devices[].Device"

Aha I see. Maybe you can figure which is which by inspecting the data? My payload specified exact modelnumber etc. Or trigger a legionella run, then you can perhaps deduct which device it was and so on.

So I found the solution :smiley:
Who wants can paste this code into the cnfiguration.yaml or into the sensors.yaml.

Short explanation:
id = id of the device; in my case marked by XXXXX
buildingID = BuildingID; in my case marked by YYYYY
X-MitsContextKey = X-MitsContextKey; in my case marked by TTTTTTTTTTTTTTT

These three codes must be replaced by your own.
You can find them as follows:
Open Firefox => go to the Melcloud page => enter your credentials, before logging in press the F12 key on your keyboard => in the opened command line click on networkanalys see attached pictures.

sensor:
  - platform: rest
    name: heat_pump_api
    resource: https://app.melcloud.com/Mitsubishi.Wifi.Client/user/ListDevices?id=XXXXX&buildingID=YYYYY
    method: GET
    headers: 
        X-MitsContextKey: 'TTTTTTTTTTTTTTTTTTTTT'
    value_template: "OK"
    scan_interval: 60
    json_attributes_path: "$..Devices[?(@.DeviceID==XXXXX)].Device"
    json_attributes:
      - CurrentEnergyConsumed
      - DailyHeatingEnergyConsumed
      - DailyHotWaterEnergyConsumed
      - DailyEnergyConsumedDate
      - HeatPumpFrequency
      - DefrostMode
  - platform: template
    sensors:
      heat_pump_power:
        friendly_name: "Heat Pump Power"
        # availability_template: "{{ is_state('sensor.heat_pump_api', 'OK') }}"
        availability_template: >-
          {{ (states("sensor.heat_pump_api") not in ["unknown", "unavailable"]) and (state_attr('sensor.heat_pump_api', 'CurrentEnergyConsumed') != None) }}
        value_template: "{{ state_attr('sensor.heat_pump_api', 'CurrentEnergyConsumed') }}"
        device_class: power
        unit_of_measurement: "kW"
        unique_id: 010320231
      heat_pump_daily_heating_energy_consumed:
        friendly_name: "Daily Heating Energy"
        # availability_template: "{{ is_state('sensor.heat_pump_api', 'OK') }}"
        availability_template: >-
          {{ (states("sensor.heat_pump_api") not in ["unknown", "unavailable"]) and (state_attr('sensor.heat_pump_api', 'DailyHeatingEnergyConsumed') != None) }}
        value_template: "{{ state_attr('sensor.heat_pump_api', 'DailyHeatingEnergyConsumed') }}"
        device_class: energy
        unit_of_measurement: "kWh"
        unique_id: 010320232
      heat_pump_daily_hot_water_energy_consumed:
        friendly_name: "Daily Hot Water Energy"
        # availability_template: "{{ is_state('sensor.heat_pump_api', 'OK') }}"
        availability_template: >-
          {{ (states("sensor.heat_pump_api") not in ["unknown", "unavailable"]) and (state_attr('sensor.heat_pump_api', 'DailyHotWaterEnergyConsumed') != None) }}
        value_template: "{{ state_attr('sensor.heat_pump_api', 'DailyHotWaterEnergyConsumed') }}"
        device_class: energy
        unit_of_measurement: "kWh"
        unique_id: 010320233
      heat_pump_daily_energy_consumed:
        friendly_name: "Daily Heat Pump Energy"
        availability_template: >-
          {{ (states("sensor.heat_pump_api") not in ["unknown", "unavailable"]) and (state_attr('sensor.heat_pump_api', 'DailyHotWaterEnergyConsumed') != None) }}
        value_template: "{{ state_attr('sensor.heat_pump_api', 'DailyHeatingEnergyConsumed') + state_attr('sensor.heat_pump_api', 'DailyCoolingEnergyConsumed') + state_attr('sensor.heat_pump_api', 'DailyHotWaterEnergyConsumed') }}"
        device_class: energy
        unit_of_measurement: "kWh"
        unique_id: 010320234
      heat_pump_frequency:
        friendly_name: "Heat Pump Frequency"
        # availability_template: "{{ is_state('sensor.heat_pump_api', 'OK') }}"
        availability_template: >-
          {{ (states("sensor.heat_pump_api") not in ["unknown", "unavailable"]) and (state_attr('sensor.heat_pump_api', 'HeatPumpFrequency') != None) }}
        value_template: "{{ state_attr('sensor.heat_pump_api', 'HeatPumpFrequency') }}"
        device_class: frequency
        unit_of_measurement: "Hz"
        unique_id: 010320235
      heat_pump_defrost_mode:
        friendly_name: "Heat Pump Defrost"
        # availability_template: "{{ is_state('sensor.heat_pump_api', 'OK') }}"
        availability_template: >-
          {{ (states("sensor.heat_pump_api") not in ["unknown", "unavailable"]) and (state_attr('sensor.heat_pump_api', 'DefrostMode') != None) }}
        value_template: "{{ state_attr('sensor.heat_pump_api', 'DefrostMode') }}"
        device_class: aqi
        unit_of_measurement: ""
        unique_id: 010320236
2 Likes

Apologies for hijacking the thread

Firstly thanks for all the contributions on this thread, it has helped me get the data from my ecodan into HA, but I was wondering if there is a way to send instructions? (such as power off/power on)

I would like to try and include some automations which would include switching the heat pump on/off but if other options were available I might be able to use them such as changing between heating regime (flow temp Vs. Compensation curve).

I had a look at the information sent to/from melcloud as described above using the F12 command when using a PC. I found one for “setatw” I think it was which looked to send something but I am not conversant in the code to know how to construct it within HA to replicate it.

Any help/advice is appreciated

Many thanks for this, it helped me right out! I am using the MELcloud integration for temps and heating water etc was not able to get power usage until adding these rest sensors :slight_smile:

As well as the daily data, the API also returns the current power consumed/delivered for me

Nice, maybe its different depending on device. I have Air to water ecodan pump. For example the hertz speed of the compressor is not correct.

I’m in the same boat. I’ve now got good information coming in, but want to send stuff out to create my own version of Homely where flow temperature can be changed on a schedule to take advantage of Time Of Use tariffs, weather forecast etc.