Luno Integration

Good day, has anyone been able to get Luno cryptocurrency information into Hassio?
All I am looking for is the current ETH and BTC pricing but updated live if possible from the Luno Exchange. Let me know if anyone has got this working. They have an API but what I know about APIs is dangerous hence the request for assistance.

Thank you

1 Like

Did you ever find a solution to this? This is something that I would like to implement to

@jarradstevenson - Nope… It seems that Luno exchange is not that popular under the Hassio community. Hopefully one day…

I have made a messy hack of it.
First, get a read-only API key from Luno.

Then get your list of account numbers from a command prompt:

curl -u apikeyid:apisecret https://api.luno.com/api/1/balance

Then create your sensors for the various accounts numbers account_id_1 to account_id_n that you have

- platform: command_line
  name: "Luno ZAR"
  command: curl -u apikeyid:apisecret https://api.luno.com/api/1/balance | jq '.balance[] | select(.account_id == "account_id_1")'
  json_attributes:
    - account_id
    - asset
    - unconfirmed
    - reserved
    - balance
  value_template: "{{ value_json.balance }}"
  scan_interval: 300

Get sensors for the various crypto-to-zar conversion rates (I used ETHZAR, XBTZAR and XRPZAR)

- platform: command_line
  name: "Luno ETHZAR"
  command: curl -u apikeyid:apisecret G -d 'pair=ETHZAR'  https://api.luno.com/api/1/ticker
  json_attributes:
    - pair
    - ask
    - last_trade
    - rolling_24_hour_volume
    - timestamp
    - status
  value_template: "{{ value_json.bid | float }}"
  scan_interval: 300

Then create template sensors for the various cryptos you have to convert to ZAR:

- platform: template
  sensors:
  
    luno_xbt_in_zar:
      friendly_name: "Luno Bitcoin in ZAR"
      value_template: "{{ (states('sensor.luno_xbtzar') | float) * (states('sensor.luno_xbt') | float ) }}"
      unit_of_measurement: "R"

    luno_xbt_savings_in_zar:
      friendly_name: "Luno Bitcoin savings in ZAR"
      value_template: "{{ (states('sensor.luno_xbtzar') | float) * (states('sensor.luno_xbt_savings') | float ) }}"
      unit_of_measurement: "R"

    luno_xrp_in_zar:
      friendly_name: "Luno XRP in ZAR"
      value_template: "{{ (states('sensor.luno_xrpzar') | float) * (states('sensor.luno_xrp') | float ) }}"
      unit_of_measurement: "R"

    luno_eth_in_zar:
      friendly_name: "Luno ETH in ZAR"
      value_template: "{{ (states('sensor.luno_ethzar') | float) * (states('sensor.luno_eth') | float ) }}"
      unit_of_measurement: "R"

    luno_wallet_in_zar:
      friendly_name: "Total Luno Wallets in ZAR"
      value_template: "{{ (states('sensor.luno_eth_in_zar') | float) + (states('sensor.luno_xbt_in_zar') | float ) + (states('sensor.luno_xbt_savings_in_zar') | float ) + (states('sensor.luno_zar') | float ) + (states('sensor.luno_xrp_in_zar') | float ) }}"
      unit_of_measurement: "R"

Bit of a hack, but works. Maybe one day when I’m big I’ll know how to code proper integrations…

1 Like

Thank you for this! I am grateful that I could add these as sensors to my HA.

Sorry for bumping this old thread.
I found that some of the functions weren’t working as intended, perhaps an update to the Luno API broke it.
For any future readers, replace the currency conversion bits:

command: curl -u apikeyid:apisecret G -d 'pair=ETHZAR'  https://api.luno.com/api/1/ticker

with

command: curl https://api.luno.com/api/1/ticker?pair=ETHZAR

Also, if you add
“unique_id:” under the name of the sensor entities, it will allow you to customize the icon from the entity settings.
For example:

friendly_name: "Luno BTC in ZAR"
unique_id: Luno_BTC_in_ZAR
1 Like

I updated mine to RESTful sensors at some point too:

- platform: rest
  name: luno_accounts_balances
  resource: https://api.luno.com/api/1/balance
  username: !secret luno_api_username
  password: !secret luno_api_password
  value_template: "OK"
  scan_interval: 300
  json_attributes:
    - balance
  
  
- platform: rest
  name: "Luno XBTZAR"
  resource: https://api.luno.com/api/1/ticker
  username: !secret luno_api_username
  password: !secret luno_api_password
  value_template: "{{ value_json.bid }}"
  scan_interval: 300
  unit_of_measurement: "R"
  json_attributes:
    - pair
    - ask
    - last_trade
    - rolling_24_hour_volume
    - timestamp
    - status
  params:
    pair: XBTZAR

- platform: rest
  name: "Luno XRPZAR"
  resource: https://api.luno.com/api/1/ticker
  username: !secret luno_api_username
  password: !secret luno_api_password
  value_template: "{{ value_json.bid }}"
  scan_interval: 300
  unit_of_measurement: "R"
  json_attributes:
    - pair
    - ask
    - last_trade
    - rolling_24_hour_volume
    - timestamp
    - status
  params:
    pair: XRPZAR

- platform: rest
  name: "Luno ETHZAR"
  resource: https://api.luno.com/api/1/ticker
  username: !secret luno_api_username
  password: !secret luno_api_password
  value_template: "{{ value_json.bid }}"
  scan_interval: 300
  unit_of_measurement: "R"
  json_attributes:
    - pair
    - ask
    - last_trade
    - rolling_24_hour_volume
    - timestamp
    - status
  params:
    pair: ETHZAR

- platform: rest
  name: "Luno Exchange Rates"
  resource: https://api.luno.com/api/1/tickers?pair=ETHZAR&pair=XRPZAR&pair=XBTZAR
  username: !secret luno_api_username
  password: !secret luno_api_password
  value_template: "OK"
  scan_interval: 300
  json_attributes:
    - tickers
1 Like