Tankmate tank level sensor

Hi all

My boss has a farm out in the sticks and has been monitoring his main irrigation tank level using a product called TankMate.

https://tankmate.com.au/products/tankmate-r3-tank-level-sensor-wifi

It works really well, but there’s no Home Assistant integration, which would be really nice.

The product does have an API, but this is way beyond my abilities, plus I’m flat out with work, studies and children to even attempt this.

Has anyone else looked into this, or would like to? (happy to donate)

curl -X 'GET' \
  'https://api.tankmate.app/status/?uid=your-UID-here' \
  -H 'accept: application/json' \
  -H 'api-key: insert-your-api-here'
{
  "R3W-90380ca79a08": {
    "deviceId": "your-device-id",
    "deviceType": "v3",
    "maxVolume": 117025,
    "maximumHeight": 1.49,
    "outletHeight": 10,
    "overflowHeight": 1.5,
    "tankArea": 78.53999999999999,
    "tankName": "Farm Tank",
    "batVoltage": 5294,
    "bootCount": 2,
    "fw": 52,
    "network": "JNT IoT",
    "rssi": -33,
    "soh": 98,
    "currentLevel": 0.487,
    "lastReading": "2024-02-05T08:08:54.600Z",
    "currentVolume": 37464,
    "currentPercent": 32
  }
}

Much appreciated

If you have got as far as retrieving data via the API the job is half done.

You then just need to consume the response using a RESTful sensor:

That’s just via the TankMate website, I wouldn’t even know where to start retrieving it.

OK, I’ve made some headway using chatGPT, but it’s not perfect.
I get the current level, but not the other values.

 - platform: rest
    name: Farm Tank
    resource: https://api.tankmate.app/status/?uid=my-UID
    json_attributes_path: "$.R3W-90380ca79a08"
    value_template: "{{ value_json.R3W-90380ca79a08.currentLevel }}"
    headers:
      accept: application/json
      api-key: my-api-key
      
    sensor:
      - platform: template
        sensors:
        farm_tank_device_id:
          friendly_name: "Farm Tank Device ID"
          value_template: "{{ state_attr('sensor.farm_tank', 'R3W-90380ca79a08').deviceId }}"
        farm_tank_device_type:
          friendly_name: "Farm Tank Device Type"
          value_template: "{{ state_attr('sensor.farm_tank', 'R3W-90380ca79a08').deviceType }}"
        farm_tank_max_volume:
          friendly_name: "Farm Tank Max Volume"
          value_template: "{{ state_attr('sensor.farm_tank', 'R3W-90380ca79a08').maxVolume }}"
      # Add more template sensors for other attributes

OK, I managed to get what I need. This is pretty rudimentary code, but it’s the best I could come up with.

sensor:  
  - platform: rest
    name: Farm Tank
    resource: https://api.tankmate.app/status/?uid=Your-UID-goes-here
    method: GET
    headers:
      accept: application/json
      api-key: your-api-key-goes-here
    value_template: "{{ value_json['yourdevice-ID-goes here']['currentLevel'] }}"
    json_attributes:
      - 'yourdevice-ID-goes here'
      
  - platform: template
    sensors:
      farm_tank_device_id:
        friendly_name: "Farm Tank Device ID"
        value_template: "{{ state_attr('sensor.farm_tank', 'yourdevice-ID-goes here').deviceId }}"
      
      farm_tank_max_volume:
        friendly_name: "Farm Tank Max Volume"
        value_template: "{{ state_attr('sensor.farm_tank', 'yourdevice-ID-goes here').maxVolume }}"
        unit_of_measurement: "L"
        device_class: volume_storage
      
      farm_tank_maximum_height:
        friendly_name: "Farm Tank Maximum Height"
        value_template: "{{ state_attr('sensor.farm_tank', 'yourdevice-ID-goes here').maximumHeight }}"
        unit_of_measurement: "m"
        device_class: distance
        
      farm_tank_outlet_height:
        friendly_name: "Farm Tank Outlet Height"
        value_template: "{{ state_attr('sensor.farm_tank', 'yourdevice-ID-goes here').outletHeight }}"
        unit_of_measurement: "m"
        device_class: distance
        
      farm_tank_overflow_height:
        friendly_name: "Farm Tank Overflow Height"
        value_template: "{{ state_attr('sensor.farm_tank', 'yourdevice-ID-goes here').overflowHeight }}"
        unit_of_measurement: "m" 
        device_class: distance
      
      farm_tank_tank_area:
        friendly_name: "Farm Tank Tank Area"
        value_template: "{{ state_attr('sensor.farm_tank', 'yourdevice-ID-goes here').tankArea }}"
        unit_of_measurement: "m2"
        
      farm_tank_tank_name:
        friendly_name: "Farm Tank Tank Name"
        value_template: "{{ state_attr('sensor.farm_tank', 'yourdevice-ID-goes here').tankName }}"
      
      farm_tank_bat_voltage:
        friendly_name: "Farm Tank Battery Voltage"
        value_template: "{{ state_attr('sensor.farm_tank', 'yourdevice-ID-goes here').batVoltage | float / 1000|round(2) }}"
        unit_of_measurement: "V"
        device_class: battery
        
      farm_tank_current_volume:
        friendly_name: "Farm Tank Current Volume"
        value_template: "{{ state_attr('sensor.farm_tank', 'yourdevice-ID-goes here').currentVolume }}"
        unit_of_measurement: "L"
        device_class: volume_storage
        
      farm_tank_current_percent:
        friendly_name: "Farm Tank Current Percentage"
        value_template: "{{ state_attr('sensor.farm_tank', 'yourdevice-ID-goes here').currentPercent }}"
        unit_of_measurement: "%"
        device_class: volume_storage

      farm_tank_last_reading:
        friendly_name: "Farm Tank Last Reading"
        value_template: "{{ state_attr('sensor.farm_tank', 'yourdevice-ID-goes here').lastReading }}"
        device_class: timestamp
        
      farm_tank_network:
        friendly_name: "Network"
        value_template: "{{ state_attr('sensor.farm_tank', 'yourdevice-ID-goes here').network }}"   
        
2 Likes

Recently purchased a Tank Mate - the fact that there was a basic integration in place (Thanks Simon!) swung the decision in favour of their device.

I’ve made a few tweaks to Simon’s excellent starting point and include them here in case of use to anyone else.

# Mofified version of the Tankmate "Farm Tank" sensor by SimonPth
# Modifications by hughhalf: 
#     * Set scan interval to 5m instead of default 30s  Data changes no more often than
#       15m and reduces load the TankMate backend
#     * Used 'tankName' as the Value_template and shifted currentLevel into template section
#       this seemed to improve handling of the 'currentLevel' value in HA cards etc
#     * Unit of measure fot outlet height is millimetres rather than metres
#     * Changed name to "Water Tank" from "Farm Tank"
#
# ToDo One Day Maybe...
#     * Abstract out UID, API Key and DeviceID to be set once at top of file 
#     * Re-write as a full integration with multi tank support etc.
#
# This version 2024-08-12a
  
sensor:   # May not need this line depending on how you include this into your HA install  
  - platform: rest
    name: Water Tank
    resource: https://api.tankmate.app/status/?uid=Your-UID-Goes-Here
    scan_interval: 300
    method: GET
    headers:
      accept: application/json
      api-key: Your-API-Key-Goes-Here
    value_template: "{{ value_json['Your-DeviceID-Goes-Here']['tankName'] }}"
    json_attributes:
      - 'Your-DeviceID-Goes-Here'
      
  - platform: template
    sensors:
      water_tank_device_id:
        friendly_name: "Water Tank Device ID"
        value_template: "{{ state_attr('sensor.water_tank', 'Your-DeviceID-Goes-Here').deviceId }}"
      
      water_tank_max_volume:
        friendly_name: "Water Tank Max Volume"
        value_template: "{{ state_attr('sensor.water_tank', 'Your-DeviceID-Goes-Here').maxVolume }}"
        unit_of_measurement: "L"
        device_class: volume_storage
      
      water_tank_maximum_height:
        friendly_name: "Water Tank Maximum Height"
        value_template: "{{ state_attr('sensor.water_tank', 'Your-DeviceID-Goes-Here').maximumHeight }}"
        unit_of_measurement: "m"
        device_class: distance
        
      water_tank_outlet_height:
        friendly_name: "Water Tank Outlet Height"
        value_template: "{{ state_attr('sensor.water_tank', 'Your-DeviceID-Goes-Here').outletHeight }}"
        unit_of_measurement: "mm"
        device_class: distance
        
      water_tank_overflow_height:
        friendly_name: "Water Tank Overflow Height"
        value_template: "{{ state_attr('sensor.water_tank', 'Your-DeviceID-Goes-Here').overflowHeight }}"
        unit_of_measurement: "m" 
        device_class: distance
      
      water_tank_tank_area:
        friendly_name: "Water Tank tank Area"
        value_template: "{{ state_attr('sensor.water_tank', 'Your-DeviceID-Goes-Here').tankArea }}"
        unit_of_measurement: "m2"
        
      water_tank_bat_voltage:
        friendly_name: "Water Tank Battery Voltage"
        value_template: "{{ state_attr('sensor.water_tank', 'Your-DeviceID-Goes-Here').batVoltage | float / 1000|round(2) }}"
        unit_of_measurement: "V"
        device_class: battery
        
      water_tank_current_volume:
        friendly_name: "Water tank Current Volume"
        value_template: "{{ state_attr('sensor.water_tank', 'Your-DeviceID-Goes-Here').currentVolume }}"
        unit_of_measurement: "L"
        device_class: volume_storage
        
      water_tank_current_percent:
        friendly_name: "Water Tank Current Percent"
        value_template: "{{ state_attr('sensor.water_tank', 'Your-DeviceID-Goes-Here').currentPercent }}"
        unit_of_measurement: "%"
        device_class: volume_storage
        
      water_tank_current_level:
        friendly_name: "Water Tank Current Level"
        value_template: "{{ state_attr('sensor.water_tank', 'Your-DeviceID-Goes-Here').currentLevel }}"
        unit_of_measurement: "m"
        device_class: distance

      water_tank_last_reading:
        friendly_name: "Water Tank Last Reading"
        value_template: "{{ state_attr('sensor.water_tank', 'Your-DeviceID-Goes-Here').lastReading }}"
        device_class: timestamp
        
      water_tank_network:
        friendly_name: "Water Tank Network"
        value_template: "{{ state_attr('sensor.water_tank', 'Your-DeviceID-Goes-Here').network }}"

3 Likes

Thanks for the YAML Hugh & Simon. I added it to my HA and have got it calling the TankMate API for my sensor, which incidentally I need to re-calibrate as I have made some guesses on the tank dimensions, so some of the readings are out.

1 Like

I’ve “recalibrated” the sensor by tweaking the tank dimensions in the app, so the reported parameters are now more realistic. Also I think a scan_interval of 2000 or longer is better given the sensor only sends updates to TankMate twice a day. The app also displays the battery % but the YAML code doesn’t calculate this. Not sure how to add this - perhaps some local calculation/formula is required?

The water tank area could do with having only 2 decimal places :slight_smile: Again, so local formula is needed to do this.

1 Like

Adding a float/round(2) to the tank area state_attr in YAML fixes the returned value to 2 decimal places.

I’ve added the following YAML to get a battery percentage. Based on my particular model of TankMate and battery type, with the app reporting 4.8V as 64%, the formula needed a divisor of 7.59, then round off to a whole number:

water_tank_bat_percent:
   friendly_name: "Water Tank Battery Percent"
   value_template: "{{ (state_attr('sensor.water_tank', 'R3W-d8bc38ea627c').batVoltage | float / 75.9)|round(0) }}"
    unit_of_measurement: "%"
    device_class: battery

1 Like

Top work guys, glad the code got you started.

Would you mind sharing your card? Yours is way prettier than mine!

Hi Simon - I’ll happily share the card when I’ve worked out how to…

Is this what you asked for?:

type: entities
entities:
  - entity: sensor.water_tank
  - entity: sensor.water_tank_bat_voltage
  - entity: sensor.water_tank_bat_percent
  - entity: sensor.water_tank_current_level
  - entity: sensor.water_tank_current_percent
  - entity: sensor.water_tank_current_volume
  - entity: sensor.water_tank_last_reading
  - entity: sensor.water_tank_max_volume
  - entity: sensor.water_tank_maximum_height
  - entity: sensor.water_tank_outlet_height
  - entity: sensor.water_tank_overflow_height
  - entity: sensor.water_tank_tank_area
  - entity: sensor.water_tank_device_id
  - entity: sensor.water_tank_network
state_color: false
1 Like

Ah, no sorry, I was looking at your post and I realised it’s just a screenshot of the app on your phone :joy:
All good, I have something drawn up anyway, I’ll share it later.

Hi Simon i came across you post, i have 3 x Tankmate sensors id like to intergrate into HA also, do you know how to grab hold of the api for these, im using chatgpt to help out as i dont have any coding experience, any help much appreciate. Alan

Hi mate, start here: