“Min Renovasjon” is a Norwegian app for getting notified of trash/recycle pickup. There is an app that covers most of Norway. It would be really nice if this could be implemented into Home Assistant.
Looks like someone over on openhab got something working. Something similar could easily be done with a rest sensor here in HA.
If it is an android app you can probably pick up the rest command with an app called packet capture. https://play.google.com/store/apps/details?id=app.greyshirts.sslcapture&hl=en
Im using restful sensor to accomplish this.
Can post the code when i get home.
That would be great!
I’ve started to look into it, but don’t know how I’m supposed to extract specific data. Like from this response, I want the dates for FraksjonId 1.
[
{
“FraksjonId”: 2,
“Tommedatoer”: [
“2019-05-16T00:00:00”,
“2019-06-13T00:00:00”
]
},
{
“FraksjonId”: 3,
“Tommedatoer”: [
“2019-05-16T00:00:00”,
“2019-06-01T00:00:00”
]
},
{
“FraksjonId”: 1,
“Tommedatoer”: [
“2019-06-01T00:00:00”,
“2019-06-27T00:00:00”
]
},
{
“FraksjonId”: 4,
“Tommedatoer”: [
“2019-06-03T00:00:00”,
“2019-07-29T00:00:00”
]
},
{
“FraksjonId”: 7,
“Tommedatoer”: [
“2019-06-03T00:00:00”,
“2019-07-01T00:00:00”
]
}
]
Paste this into Home Assistant’s Template Editor and you can experiment with the template to see how it works:
{% set x = [{ "FraksjonId": 2,
"Tommedatoer": [
"2019-05-16T00:00:00",
"2019-06-13T00:00:00"
]},
{ "FraksjonId": 3,
"Tommedatoer": [
"2019-05-16T00:00:00",
"2019-06-01T00:00:00"
]},
{ "FraksjonId": 1,
"Tommedatoer": [
"2019-06-01T00:00:00",
"2019-06-27T00:00:00"
]},
{ "FraksjonId": 4,
"Tommedatoer": [
"2019-06-03T00:00:00",
"2019-07-29T00:00:00"
]},
{ "FraksjonId": 7,
"Tommedatoer": [
"2019-06-03T00:00:00",
"2019-07-01T00:00:00"
]}] %}
a) {{ x[2] }}
b) {{ x[2].Tommedatoer[0] }}
------
{% for i in range(x | length) %}
{%- if x[i].FraksjonId == 1 -%}
c) {{ x[i].Tommedatoer[0] }}
{%- endif -%}
{% endfor %}
Here are the results in the Template Editor:
Awesome, my templates are done with your help, my friend! Thanks
Someone has already made a custom component, that’s the one I’m using. https://github.com/eyesoft/home-assistant-custom-components
Hi, how did you find your correct parameters? (streetcode & countyid)
Go to your kommunen tømmekalender website: for example
Assuming you are using Chrome, right click on the website and click inspect. Click on Network tab
Enter your address on the website and press enter
Go back to your Network Inspection panel and Ctril+F search for your street name. It will jump to preview panel but if you go back to Header and scroll to the bottom, you will find everything you need.
Update:
It’s better to double check the FraksjonId using the same method as well. The FraksjonId mapping for my kommune is different from the author has written on Github
Thought I’d paste in my setup in case it can be of assistance:)
You will have to get a RenovasjonsAppKey through the developer tools in a browser, in Chrome you can find it in the Network-tab in some of the calls there after you do a search.
sensor:
- platform: rest
scan_interval: 1800
name: Renovasjon Restavfall
device_class: timestamp
resource: https://norkartrenovasjon.azurewebsites.net/proxyserver.ashx?server=https://komteksky.norkart.no/komtek.renovasjonwebapi/api/tommekalender/?kommunenr=926&gatenavn=%C3%98vreberg%20&gatekode=092604000&husnr=4
headers:
Content-Type: undefined
Kommunenr: 926
RenovasjonAppKey: YOUR-KEY-HERE
value_template: '{{(as_timestamp(value_json[0].Tommedatoer[0]) + 32400) | timestamp_utc}}'
- platform: rest
scan_interval: 1800
name: Renovasjon Papp og Papir
device_class: timestamp
resource: https://norkartrenovasjon.azurewebsites.net/proxyserver.ashx?server=https://komteksky.norkart.no/komtek.renovasjonwebapi/api/tommekalender/?kommunenr=926&gatenavn=%C3%98vreberg%20&gatekode=092604000&husnr=4
headers:
Content-Type: undefined
Kommunenr: 926
RenovasjonAppKey: YOUR-KEY-HERE
value_template: '{{(as_timestamp(value_json[2].Tommedatoer[0]) + 32400) | timestamp_utc}}'
- platform: rest
scan_interval: 1800
name: Renovasjon Våtorganisk
device_class: timestamp
resource: https://norkartrenovasjon.azurewebsites.net/proxyserver.ashx?server=https://komteksky.norkart.no/komtek.renovasjonwebapi/api/tommekalender/?kommunenr=926&gatenavn=%C3%98vreberg%20&gatekode=092604000&husnr=4
headers:
Content-Type: undefined
Kommunenr: 926
RenovasjonAppKey: YOUR-KEY-HERE
value_template: '{{(as_timestamp(value_json[1].Tommedatoer[0]) + 32420) | timestamp_utc}}'
- platform: rest
scan_interval: 1800
name: Renovasjon Plast
device_class: timestamp
resource: https://norkartrenovasjon.azurewebsites.net/proxyserver.ashx?server=https://komteksky.norkart.no/komtek.renovasjonwebapi/api/tommekalender/?kommunenr=926&gatenavn=%C3%98vreberg%20&gatekode=092604000&husnr=4
headers:
Content-Type: undefined
Kommunenr: 926
RenovasjonAppKey: YOUR-KEY-HERE
value_template: '{{(as_timestamp(value_json[3].Tommedatoer[0]) + 32420) | timestamp_utc}}'
I also made some binary sensors that let me know (through a Google Home automation) when they are picking up the trash tomorrow:
binary_sensor:
- platform: template
sensors:
renovation_general_waste_tomorrow:
friendly_name: "Varsel Renovasjon Restavfall"
value_template: "{{((as_timestamp(states('sensor.renovasjon_restavfall')) - (3600 * 13)) | timestamp_local) < (as_timestamp(now()) | timestamp_local)}}"
renovation_paper_tomorrow:
friendly_name: "Varsel Renovasjon Papp og Papir"
value_template: "{{((as_timestamp(states('sensor.renovasjon_papp_og_papir')) - (3600 * 13)) | timestamp_local) < (as_timestamp(now()) | timestamp_local)}}"
renovation_plastic_tomorrow:
friendly_name: "Varsel Renovasjon Plast"
value_template: "{{((as_timestamp(states('sensor.renovasjon_plast')) - (3600 * 13)) | timestamp_local) < (as_timestamp(now()) | timestamp_local)}}"
renovation_organic_tomorrow:
friendly_name: "Varsel Renovasjon Bioavfall"
value_template: "{{((as_timestamp(states('sensor.renovasjon_vatorganisk')) - (3600 * 13)) | timestamp_local) < (as_timestamp(now()) | timestamp_local)}}"
Hello and thank you for the code.
In our kommune we have 5 recyceling fractions. Do you know how to add the fifth?
I have tried the following code without any luck.
- platform: rest
scan_interval: 1800
name: Glass og metall
device_class: timestamp
resource: https://norkartrenovasjon.azurewebsites.net/proxyserver.ashx?server=https://komteksky.norkart.no/komtek.renovasjonwebapi/api/tommekalender/?kommunenr=529&gatenavn=Kl%C3%B8vervegen%20&gatekode=052903600&husnr=10A
headers:
Content-Type: undefined
Kommunenr: 529
RenovasjonAppKey: CORRECTAPPKEY
value_template: '{{(as_timestamp(value_json[4].Tommedatoer[0]) + 32420) | timestamp_utc}}'
It’s a little hard to tell without pulling down the JSON reply and having a look, the code you posted should work as from the data I’m getting, every FraksjonID is a separate array item. It is possible that there are more array items in the list that do not have the required data?
My array just looks like this:
[
{
"FraksjonId": 1,
"Tommedatoer": [
"2019-08-05T00:00:00",
"2019-08-19T00:00:00"
]
},
{
"FraksjonId": 3,
"Tommedatoer": [
"2019-08-05T00:00:00",
"2019-08-12T00:00:00"
]
},
{
"FraksjonId": 2,
"Tommedatoer": [
"2019-08-20T00:00:00",
"2019-09-17T00:00:00"
]
},
{
"FraksjonId": 7,
"Tommedatoer": [
"2019-08-20T00:00:00",
"2019-09-17T00:00:00"
]
}
]
I had a quick look, and the reply from your kommune should put the fifth fraction at value_json[4].Tommedatoer[0], so I am at a loss as to why it wouldn’t work.
Also, having had a look at it, it turns out the AppId seems to be the same as in my kommune, although I don’t know whether it’s stored in a cookie and unique to every user or just the same for everyone everywhere…
Your kommunes reply:
[
{
"FraksjonId": 4,
"Tommedatoer": [
"2019-08-12T00:00:00",
"2019-10-07T00:00:00"
]
},
{
"FraksjonId": 7,
"Tommedatoer": [
"2019-08-12T00:00:00",
"2019-09-09T00:00:00"
]
},
{
"FraksjonId": 2,
"Tommedatoer": [
"2019-08-16T00:00:00",
"2019-09-13T00:00:00"
]
},
{
"FraksjonId": 3,
"Tommedatoer": [
"2019-08-16T00:00:00",
"2019-08-30T00:00:00"
]
},
{
"FraksjonId": 1,
"Tommedatoer": [
"2019-08-30T00:00:00",
"2019-09-27T00:00:00"
]
}
]
The index of the dict is different every time after a waste collection. Is it possible to index using the FraksjonID?
I’m not sure I’m afraid, I haven’t really experimented much with parsing logic in HA… To be honest it took me some time to figure out how to just get the value by index. Maybe someone else has an idea?
I’m using this because the index changes randomly. Problably not the most effective way to do it, but it gets the job done.
Probably can make it work for @HansOHG too…?
sensor:
- platform: rest
name: Avfall rest
value_template: >
{% for entry in value_json %}
{% if entry.FraksjonId == 1 %}
{{ entry.Tommedatoer[0] }}
{% endif %}
{% endfor %}
method: GET
scan_interval: 43200 # once every 12 hours
resource: https://norkartrenovasjon.azurewebsites.net/proxyserver.ashx?server=https://komteksky.norkart.no/komtek.renovasjonwebapi/api/tommekalender/?kommunenr=XXX&gatenavn=XXX&gatekode=XXX&husnr=XXX
force_update: true
headers:
Host: norkartrenovasjon.azurewebsites.net
User-Agent: Home Assistant
Referer: http://norkartrenovasjon.azurewebsites.net/XXX
RenovasjonAppKey: XXX
Kommunenr: XXX
- platform: rest
name: Avfall mat
value_template: >
{% for entry in value_json %}
{% if entry.FraksjonId == 3 %}
{{ entry.Tommedatoer[0] }}
{% endif %}
{% endfor %}
method: GET
scan_interval: 43200 # once every 12 hours
resource: https://norkartrenovasjon.azurewebsites.net/proxyserver.ashx?server=https://komteksky.norkart.no/komtek.renovasjonwebapi/api/tommekalender/?kommunenr=XXX&gatenavn=XXX&gatekode=XXX&husnr=XXX
force_update: true
headers:
Host: norkartrenovasjon.azurewebsites.net
User-Agent: Home Assistant
Referer: http://norkartrenovasjon.azurewebsites.net/XXX
RenovasjonAppKey: XXX
Kommunenr: XXX
- platform: rest
name: Avfall papir
value_template: >
{% for entry in value_json %}
{% if entry.FraksjonId == 2 %}
{{ entry.Tommedatoer[0] }}
{% endif %}
{% endfor %}
method: GET
scan_interval: 43200 # once every 12 hours
resource: https://norkartrenovasjon.azurewebsites.net/proxyserver.ashx?server=https://komteksky.norkart.no/komtek.renovasjonwebapi/api/tommekalender/?kommunenr=XXX&gatenavn=XXX&gatekode=XXX&husnr=XXX
force_update: true
headers:
Host: norkartrenovasjon.azurewebsites.net
User-Agent: Home Assistant
Referer: http://norkartrenovasjon.azurewebsites.net/XXX
RenovasjonAppKey: XXX
Kommunenr: XXX
- platform: rest
name: Avfall plast
value_template: >
{% for entry in value_json %}
{% if entry.FraksjonId == 7 %}
{{ entry.Tommedatoer[0] }}
{% endif %}
{% endfor %}
method: GET
scan_interval: 43200 # once every 12 hours
resource: https://norkartrenovasjon.azurewebsites.net/proxyserver.ashx?server=https://komteksky.norkart.no/komtek.renovasjonwebapi/api/tommekalender/?kommunenr=XXX&gatenavn=XXX&gatekode=XXX&husnr=XXX
force_update: true
headers:
Host: norkartrenovasjon.azurewebsites.net
User-Agent: Home Assistant
Referer: http://norkartrenovasjon.azurewebsites.net/XXX
RenovasjonAppKey: XXX
Kommunenr: XXX
- platform: rest
name: Avfall spesial
value_template: >
{% for entry in value_json %}
{% if entry.FraksjonId == 24 %}
{{ entry.Tommedatoer[0] }}
{% endif %}
{% endfor %}
method: GET
scan_interval: 43200 # once every 12 hours
resource: https://norkartrenovasjon.azurewebsites.net/proxyserver.ashx?server=https://komteksky.norkart.no/komtek.renovasjonwebapi/api/tommekalender/?kommunenr=XXX&gatenavn=XXX&gatekode=XXX&husnr=XXX
force_update: true
headers:
Host: norkartrenovasjon.azurewebsites.net
User-Agent: Home Assistant
Referer: http://norkartrenovasjon.azurewebsites.net/XXX
RenovasjonAppKey: XXX
Kommunenr: XXX
- platform: template
sensors:
avfall_rest_template:
friendly_name: Rest
value_template: "{{ as_timestamp(states('sensor.avfall_rest')) | timestamp_custom('%d/%m') }}"
avfall_mat_template:
friendly_name: Mat
value_template: "{{ as_timestamp(states('sensor.avfall_mat')) | timestamp_custom('%d/%m') }}"
avfall_papir_template:
friendly_name: Papir
value_template: "{{ as_timestamp(states('sensor.avfall_papir')) | timestamp_custom('%d/%m') }}"
avfall_plast_template:
friendly_name: Plast
value_template: "{{ as_timestamp(states('sensor.avfall_plast')) | timestamp_custom('%d/%m') }}"
avfall_spesial_template:
friendly_name: Spesial
value_template: "{{ as_timestamp(states('sensor.avfall_spesial')) | timestamp_custom('%d/%m') }}"
Could someone please give a “complete guide/tutorial” on how to install this?
The key is something like aac8b502-xxxx-yyyy-xxxx-xxxxxxxxxxxx ?
Referer like “Referer: https://www.sirkula.no/hjemme-hos-deg/tommekalender/”