How can I send a notification for changing entity sensor

Hi,

I would like to get push notifications on my android phone for a changing entity sensor, for a Trash pickup.
It uses hacs with the Dutch Afvalwijzer. I have an Entity card on my Overview that changes when the next pickup date is for a the Trashcan.
image

I would like to get notifications the day before the specific trashcan.
Like Next wednesday the GFT needs to go I would like to get a notification tuesday (evening if possible)

I hope you guys can help me set this up.

Post the state of the sensor as seen in developer tools / state. Also the entity id.

That integration uses the attribute Days_until for that
So when its 0 its today, 1 the day before.
In my case i get a notify at 20:00 the day before and 6:30 on the day which bin it is.

That makes it easy:

trigger:
  - platform: time
    at: '18:00' # or whatever time you want to receive the notification
condition:
  - condition: state
    entity_id: sensor.your_garbage_sensor_here
    attribute: Days_until # check the capitalisation of this
    state: 1

Owhh that would even be nicer to have both of the times.
Mind me sending your configuration so I can take a look at it.

I’m very new to Home Assistant and all the programming.

Sure, keep in mind that you have a sensor for each of the garbage types.
So for the GFT i have these 2:

Warning at the day before

alias: GFT morgen
description: ''
trigger:
  - platform: time
    at: '18:00'
condition:
  - condition: state
    entity_id: sensor.meerlanden_gft
    state: 1
    attribute: Days_until
action:
  - service: notify.notify_mobiles
    data:
      message: GFT Bak morgen aan de weg
      title: GFT Bak Morgen
mode: single

Warning at the day itself:

alias: GFT vandaag
description: ''
trigger:
  - platform: time
    at: '06:30'
condition:
  - condition: state
    entity_id: sensor.meerlanden_gft
    state: 0
    attribute: Days_until
action:
  - service: notify.notify_mobiles
    data:
      message: GFT Bak vandaag aan de weg
      title: GFT Bak vandaag
mode: single

Copy and paste for the others. (sensor.meerlanden_pmd, sensor.meerlanden_papier)
Replace meerlanden with your own service ofcourse :smiley:

I made a notify_mobiles group which has the phones in it you need to notify

In configuration.yaml :

notify:
  - name: notify_mobiles
    platform: group
    services:
      - service: mobile_app_toestel_1
      - service: mobile_app_toestel_2

Where did you paste the Triggers for the sensor itself?
Does this has to go into the configuration.yaml aswell

So the trigger is the time of day, NOT the sensor.
So each day at that time i check if the sensor is at value 1 or 0
And that is the first step of the automation

Okay so I made the group, just wanted to check if I did it correctly with my phone.
image

What goes for the Sensor for each bin, where did you make these.
Thanks so far for helping me out on this one!

The sensor were added when u activated the Afval integration.
Go to the developer page and select STATES at the top. Then under Current Entities click Set State.
In the entity field you can type out “sensor.purmerend” and it will show the 3 sensors (GTF, Papier, Rest or something like that)
Those are the sensors you will want to use in your automation. In my case its Meerlanden, so the sensors would be sensor.meerlanden_gft, sensor.meerlanden_papier, sensor.meerlanden_pmd.
You just need to look how yours are named.

Hey Dujith,

I did everything you said and installed the automation. When I do “RUN ACTIONS” it works fine.
But the schedule doesn’t work. it’s not giving me the push notifications.

And it comes back with a pretty big trace.

Trace log

{
“trace”: {
“last_step”: “condition/0/entity_id/0”,
“run_id”: “579c89c568d57d912d0a1c3031374071”,
“state”: “stopped”,
“script_execution”: “failed_conditions”,
“timestamp”: {
“start”: “2022-02-01T19:10:00.001960+00:00”,
“finish”: “2022-02-01T19:10:00.002341+00:00”
},
“domain”: “automation”,
“item_id”: “1643644232218”,
“trigger”: “time”,
“trace”: {
“trigger/0”: [
{
“path”: “trigger/0”,
“timestamp”: “2022-02-01T19:10:00.002128+00:00”,
“changed_variables”: {
“this”: {
“entity_id”: “automation.afvalbeheer_gft_morgen”,
“state”: “on”,
“attributes”: {
“last_triggered”: “2022-02-01T18:45:08.473095+00:00”,
“mode”: “single”,
“current”: 0,
“id”: “1643644232218”,
“friendly_name”: “Afvalbeheer - GFT (morgen)”
},
“last_changed”: “2022-02-01T19:05:52.718484+00:00”,
“last_updated”: “2022-02-01T19:05:52.718484+00:00”,
“context”: {
“id”: “e63419d040133f9593e365ae7eaee2fc”,
“parent_id”: null,
“user_id”: null
}
},
“trigger”: {
“id”: “0”,
“idx”: “0”,
“platform”: “time”,
“now”: “2022-02-01T20:10:00.001209+01:00”,
“description”: “time”,
“entity_id”: null
}
}
}
],
“condition/0”: [
{
“path”: “condition/0”,
“timestamp”: “2022-02-01T19:10:00.002210+00:00”,
“result”: {
“result”: false
}
}
],
“condition/0/entity_id/0”: [
{
“path”: “condition/0/entity_id/0”,
“timestamp”: “2022-02-01T19:10:00.002251+00:00”,
“result”: {
“result”: false,
“state”: 1,
“wanted_state”: “1”
}
}
]
},
“config”: {
“id”: “1643644232218”,
“alias”: “Afvalbeheer - GFT (morgen)”,
“description”: “”,
“trigger”: [
{
“platform”: “time”,
“at”: “20:10:00”
}
],
“condition”: [
{
“condition”: “state”,
“entity_id”: “sensor.purmerend_gft”,
“state”: “1”,
“attribute”: “Days_until”
}
],
“action”: [
{
“service”: “notify.notify_mobiles”,
“data”: {
“message”: “GFT bak morgen aan straat”,
“title”: “GFT bak morgen”
}
}
],
“mode”: “single”
},
“blueprint_inputs”: null,
“context”: {
“id”: “45fc7962812b74305dcd6f973636ec0f”,
“parent_id”: null,
“user_id”: null
}
},
“logbookEntries”: []
}

Hope you can help me out on this one, as I can’t seem to find the problem as the state looks correct for me.

can u post the automation.
And when u paste code, make sure its between ``` (so trippel at the start and trippel at the end)

alias: Afvalbeheer - GFT (morgen)
description: ''
trigger:
  - platform: time
    at: '20:00:00'
condition:
  - condition: state
    entity_id: sensor.purmerend_gft
    attribute: Days_until
    state: '''1'''
action:
  - service: notify.notify_mobiles
    data:
      message: GFT bak morgen aan straat
      title: GFT bak morgen
mode: single

This is what the automation says, when I select yaml.
Hope this helps

The state in the condition is invalid.
Keep it in yaml mode and use
state: 1

In gui mode the state will only accept a string.
You could use numeric_state but that one only has “below, above” for the value.

See my code i posted a few post back to see the yaml example.

Been thinking about this and i think the cleaner way is to use a template. That way the GUI wont get broken.

alias: GFT morgen
description: ''
trigger:
  - platform: time
    at: '18:00'
condition:
  - condition: template
    value_template: '{{state_attr(''sensor.meerlanden_pmd'', ''Days_until'') == 1}}'
action:
  - service: notify.notify_mobiles
    data:
      message: GFT Bak morgen aan de weg
      title: GFT Bak Morgen
mode: single

In Which:

value_template: '{{state_attr(''sensor.meerlanden_pmd'', ''Days_until'') == 1}}'

Will need to be changed to your own sensor. So that would be:

value_template: '{{state_attr(''sensor.purmerend_gft'', ''Days_until'') == 1}}'

Thanks Dujith!

This works just tested it out by changing the 1 to 0 and the time.
Everything seems to work fine now.

No problem, just remember that your best friend is the Developer Tools page.
It shows what data is inside entities and how you can call that data. For example on the Template page you can insert that value template and see what it does.

1 Like