Homey
  • Homey Automations
  • Aggregated state
    • Person presence
      • Geofency and webhooks
    • Home state
    • Room and floor presence v2
    • Room and floor presence v1
    • Time table
    • Dark or bright
    • TV
    • Ventilation
      • CO2
      • Humidity bathrooms
  • Lighting
    • Scenes
    • Scene activations
  • Rooms
    • Childrens room
    • Guest room
    • Bathrooms
  • Advanced API usage
    • Getting a bearer token
  • Battery
    • Battery tracking
  • Custom integrations
    • Influxdb and Grafana
    • Flexit ventilation
    • Water metering
    • Telia data plan
    • Trondheim folkebibliotek
    • SBanken
    • Badetemperatur
    • Is it rainy? (yr.no)
  • Music
    • Music
  • Voice
    • Setup
    • Overview
Powered by GitBook
On this page

Was this helpful?

  1. Custom integrations

SBanken

Få kontostatus for dine kontoer i Sbanken. Spesielt aktuelt for barnekontoer, hvor det er mangelfull mulighet for å hente ut saldo.

Dette homeyscriptet vil bruke sbankens API for å hente ut kontostatus.

Det du må gjøre er å registrere en klient i sbanken beta utvikler portal. Sette fødselsnummer i koden under som customerID. Så må du bruke API-et for å hente ut en account ID for den kontoen du vil ha status for.

sbanken.js
let customerId = 'xxxfødselsnummerxxx'
let b = xxx base64encoded clientid : secret ....'
let tokenEndpoint = 'https://auth.sbanken.no/identityserver/connect/token'

// var basicAuth = btoa(encodeURIComponent(clientid) + ":" + encodeURIComponent(secret));
// console.log("basic ", basicAuth)

const response = await fetch(tokenEndpoint, {
  "headers": {
    "accept": "application/json",
    "authorization": "Basic " + b,
    "content-type": "application/x-www-form-urlencoded; charset=utf-8"
  },
  "body": 'grant_type=client_credentials',
  "method": "POST"
});
let data = await response.json()
var token = data['access_token']

async function getAPI(path) {
    const baseURL = 'https://api.sbanken.no/exec.bank/api/v1'
    let resp = await fetch(baseURL + path, {
        "headers": {
            "accept": "application/json",
            "authorization": "Bearer " + token,
            "content-type": "application/json",
            "customerId": customerId
        },
        "method": "GET"
    });
    let data = await resp.json()
    return data
}

// Note.. You have to play with the API in postman to get the account ID that you would like to get status from

let r = await getAPI('/Accounts/xxx_accountid_xxx')
console.log("=== Results ===")
console.log(r)

await setTagValue("sbanken_linnea", {type: 'number', title:'Linnea konto'}, r.item.available)

//console.log("response", data)
PreviousTrondheim folkebibliotekNextBadetemperatur

Last updated 4 years ago

Was this helpful?