Issue with sensor

I’m trying to use HA to track my expenses using emails I get from Chase based on this tutorial: https://thewindev.net/tracking-expenses-in-home-assistant

I keep getting config errors and I’m so confused. I’m a newbie, so go easy on me. :. . :slight_smile:

I’m trying to use HA to track my expenses using emails I get from Chase based on this tutorial: https://thewindev.net/tracking-expenses-in-home-assistant

I keep getting config errors and I’m so confused. I’m a newbie, so go easy on me. :. . :slight_smile:

last_expense:
    friendly_name: Last expense
    unit_of_measurement: '$'
    value_template: >
        '{{ state_attr('sensor.chase_email',Your Debit Card Transaction') | regex_findall_index("/\$([0-9]+[\.,0-9]*)/") }}'
    attribute_templates:
      seller: >        
          '{{ state_attr('sensor.chase_email','Your Debit Card Transaction') | regex_findall_index("(?s)(?<=to ).+?(?=on)") }}'
      date: >        
          '{{ state_attr('sensor.chase_email','Your Debit Card Transaction') | regex_findall_index("(?s)(?<=on ).+?(?=at)") }}'
      time: >        
          '{{ state_attr('sensor.chase_email','Your Debit Card Transaction') | regex_findall_index("(?s)(?<=at ).+?(?=exceeded)") }}'

Here’s a copy of sensor.chase_email which isn’t showing in developer tools:

sensor:
  - platform: imap_email_content
    name: chase_email
    server: imap.gmail.com
    port: 993
    username: ******
    password: ******
    folder: Chase
    senders:
      - [email protected]

Please format your code properly using the </> button in the editor, or with three backticks before and after the code. See rule 11 here:
https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371/3

Once you’ve done that, please also include a screenshot of Developer Tools / States showing us what sensor.chase_email looks like, but with sensitive info blacked out of course! Like this, but for your sensor:

Thank you!

That’s the first problem to solve, then. The template sensors don’t have anything to read if this sensor isn’t available.

See if there’s anything under Configuration / Logs suggesting a connection error.

You say you’re a newbie: presumably you have other sensors set up and working, and your HA setup is working other than this issue?

I’m back and I finally got “sensor.chase_email” to work and show up in developer tools.

sensor:
  - platform: imap_email_content
    name: chase_email
    server: imap.gmail.com
    port: 993
    username: redacted
    password: redacted
    folder: Chase
    senders:
      - [email protected]

I still can’t get the template sensor working.

I should also add this to configuration.yaml right?

last_expense:
  friendly_name: Last expense
  unit_of_measurement: '$'
  value_template: >
    {{ state_attr('sensor.chase_email','Your Debit Card Transaction') | regex_findall_index("/\$([0-9]+[\.,0-9]*)/") }}
  attribute_templates:
    seller: >        
      {{ state_attr('sensor.chase_email','Your Debit Card Transaction') | regex_findall_index("(?s)(?<=to ).+?(?=on)") }}
    date: >        
      {{ state_attr('sensor.chase_email','Your Debit Card Transaction') | regex_findall_index("(?s)(?<=on ).+?(?=at)") }}
    time: >        
      {{ state_attr('sensor.chase_email','Your Debit Card Transaction') | regex_findall_index("(?s)(?<=at ).+?(?=exceeded)") }}

When i check the configuration, i get “Component error: last_expense - Integration ‘last_expense’ not found.”

That last_expense block should be under the sensor: section thus [docs]:

sensor:
  - platform: template
    sensors:
      last_expense:
(etc)

Once that’s done, if it’s still not working, please include a screenshot of Developer Tools / States showing us what sensor.chase_email looks like, as per my prior post.

Your response did help me get my sensor integrated into the platform. I can see “chase_email” in developer tools and I was also able to get the email integration working. Here is the IMAP email integration sensor:

sensor:
  - platform: imap_email_content
    name: chase_email
    server: imap.gmail.com
    port: 993
    username: redacted
    password: redacted
    folder: Chase
    senders:
      - [email protected]

Here is the last_expense sensor:

    sensors:
      last_expense:
         friendly_name: Last expense
         unit_of_measurement: '$'
         value_template: >
           "{{ state_attr('sensor.chase_email','Your Debit Card Transaction') | regex_findall_index("/\$([0-9]+[\.,0-9]*)/") }}"
         attribute_templates:
           seller: >        
             "{{ state_attr('sensor.chase_email','Your Debit Card Transaction') | regex_findall_index("(?s)(?<=to ).+?(?=on)") }}"
           date: >        
             "{{ state_attr('sensor.chase_email','Your Debit Card Transaction') | regex_findall_index("(?s)(?<=on ).+?(?=at)") }}"
           time: >        
             "{{ state_attr('sensor.chase_email','Your Debit Card Transaction') | regex_findall_index("(?s)(?<=at ).+?(?=exceeded)") }}"

Here’s a screenshot of it in developer tools.
devtools

I can get the sensor to pull up in lovelace, but not seeing any of the data from the regex. I think the regex is wrong.
The emails I get from Chase contain this in the email body:

A $15.00 debit card transaction to Store Whatever on Mar 28, 2021 at 2:35 PM ET exceeded your $0.00 set Alert limit.

Can you please help?

Capture

So it looks as though you had some valid data in overnight (the purple section until “28 minutes ago”) but at the time of taking the screenshot, the sensor had gone to unknown state and the template sensors will therefore also fail.

We’d need to see your screenshot again, including State and Attribute columns, when there is some data in place.

Is this what you mean?

No. In the section I’ve marked in red here:

image

you had some data in that sensor. We need you to take that screenshot during one of those periods. I don’t know what caused the sensor to go back to being unknown 28 minutes before you took the screenshot — restarted HA perhaps?

At that point, I’d expect to see something in the States and Attributes columns, more than the current unknown state and friendly_name attribute.