Email exists = do something

I want to make HA to know and show whether the electricity bill is paid, because sometimes I forgot as I’m still doing it manually just to find better discounts.

Every time the payment went through, I get an email from the provider, which is now forwarded to the dedicated email (gmail) under specific label for this HA project.

I want to make automation that toggle the boolean I’ve set up if that particular email exists within the current month (meaning my bill is paid) and will notify me to pay if the toggle is off at 19th as the cutoff is at 20th.

Can anyone help me? I get overwhelmed and confused by the docs (I’m dyslexic)

Hi, start by reading this: Google Mail - Home Assistant :blush:

I think what you are looking for is the IMAP integration not the Gmail integration.

Just be forewarned… the IMAP integration is highly configurable, so there are multiple ways to achieve what you have described.

Gmail treats labels as folders, so use the label you are applying instead of “INBOX” in the Folder field when setting up the sensor.

Automation Sketch
triggers:
  - id: 'off'
    trigger: time
    hour: "00:01:00"
    variables:
      second_condition: "{{ now().day == 1 }}"
  - id: 'on'
    trigger: state
    entity_id: sensor.imap_EXAMPLE
    not_to:
      - unknown
      - unavailable
    not_from:
      - unknown
      - unavailable
    variables:
      second_condition: "{{ trigger.to_state.state | int > trigger.from_state.state | int }}"
conditions: 
  - condition: template
    value_template: "{{ second_condition }}"
actions:
  - action: input_boolean.turn_{{ trigger.id }}
    target:
      entity_id: input_boolean.EXAMPLE

What this automation does:

  1. One minute past midnight on the first day of each month the boolean will be turned off.
  2. When the state of the IMAP sensor increases in value (a new email is received that matches the criteria) the input boolean will be turned on.

If you are unable to get only the specific target emails included using Google’s filtering and the IMAP search criteria, a template sensor will likely be needed and the automation sketch above may need significant changes.

For the scheduled notification automation, trigger options include:

  • A combination of a Time trigger and a day-limiting condition (as shown in the sketch above)
  • A Calendar trigger based on a calendar event set to repeat monthly
2 Likes