thompy93
(Thomas)
January 15, 2022, 12:46am
1
Hi
Every time I restart home assistant the imap sensor will read every unread email and report them as state change. This is troublesome as I was hoping to use the email notification from a Reolink camera in a automation. But the automation will trigger multiple times after a restart. Any way around this?
My config and automation
##IMAP GMAIL
- platform: imap_email_content
server: imap.gmail.com
name: reolink_mail
port: 993
username: [email protected]
password: xxxxxxx
scan_interval: 30
senders:
- [email protected]
alias: Reolink notification
description: ''
trigger:
- platform: state
entity_id: sensor.reolink_mail
attribute: subject
condition: []
action:
- service: notify.mobile_app_thomas_mobil
data:
message: >-
{{ state_attr('sensor.reolink_mail','subject').split(' ')[0] }} {{
state_attr('sensor.reolink_mail','subject').split(' ')[1] }} {{
state_attr('sensor.reolink_mail','subject').split(' ')[5] }} {{
state_attr('sensor.reolink_mail','subject').split(' ')[7] }}
mode: single
thompy93
(Thomas)
January 15, 2022, 7:21pm
2
For now I created a filter in gmail for email recieved from reolink account and older_than:1h which marks them as read.
scottg489
(Scott G.)
January 17, 2022, 10:27pm
3
I’m having this problem too. Thanks for the workaround. It would be nice if this was fixed natively, though.
Seems like there’s some movement here:
home-assistant:dev
← smcpeck:imap_email_content_keep-and-daysback-impl
opened 04:53AM - 13 Jan 22 UTC
<!--
You are amazing! Thanks for contributing to our project!
Please, DO N… OT DELETE ANY TEXT from this template! (unless instructed).
-->
## Proposed change
<!--
Describe the big picture of your changes here to communicate to the
maintainers why we should accept this pull request. If it fixes a bug
or resolves a feature request, be sure to link to that issue in the
additional information section.
-->
For my use case, I am using e-mail to know the last time some event happened. Thus, I want the sensor to hold on to that information until the next e-mail comes (maybe a few days down the road).
To accomplish the desired functionality for my use case, I added a new, optional `keep` configuration option that will tell the sensor to keep the previously processed e-mail instead of sending `None` back causing the sensor to read `Unknown`.
A side effect of this is that the sensor value is lost on a restart. Other sensors don't particularly have this problem because they query the status of a light switch or thermostat or whatever and restore the sensor value to whatever the current state is. To allow for restoration of the previous state for my use case, I added another optional config value called `daysback` that will alter the `SINCE` IMAP query to look before the current date. Once this happens, subsequent queries are all `UID`-based, so it's just that initial check for an e-mail that is affected.
The `daysback` solution is obviously not perfect, so I'm open to explore a different implementation approach.
## Type of change
<!--
What type of change does your PR introduce to Home Assistant?
NOTE: Please, check only 1! box!
If your PR requires multiple boxes to be checked, you'll most likely need to
split it into multiple PRs. This makes things easier and faster to code review.
-->
- [ ] Dependency upgrade
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [x] New feature (which adds functionality to an existing integration)
- [ ] Breaking change (fix/feature causing existing functionality to break)
- [ ] Code quality improvements to existing code or addition of tests
## Additional information
<!--
Details are important, and help maintainers processing your PR.
Please be sure to fill out additional details, if applicable.
-->
Some refactoring clean-up has also been added. I noticed that a `UID` request of `None` was taking place, so I guarded against that here and added some more logging. Being that both of these new config parameters are optional, it should not have any unintended side effects on existing configurations.
I've tested this a good deal locally.
Hoping for a review from @isk0001y (last one to PR into this integration from what I can see)
- This PR is related to issue: #40701 #35975
- Link to documentation pull request: https://github.com/home-assistant/home-assistant.io/pull/21172
## Checklist
<!--
Put an `x` in the boxes that apply. You can also fill these out after
creating the PR. If you're unsure about any of them, don't hesitate to ask.
We're here to help! This is simply a reminder of what we are going to look
for before merging your code.
-->
- [x] The code change is tested and works locally.
- [ ] Local tests pass. **Your PR cannot be merged unless tests pass**
- [x] There is no commented out code in this PR.
- [x] I have followed the [development checklist][dev-checklist]
- [x] The code has been formatted using Black (`black --fast homeassistant tests`)
- [ ] Tests have been added to verify that the new code works.
If user exposed functionality or configuration variables are added/changed:
- [x] Documentation added/updated for [www.home-assistant.io][docs-repository]
If the code communicates with devices, web services, or third-party tools:
- [x] The [manifest file][manifest-docs] has all fields filled out correctly.
Updated and included derived files by running: `python3 -m script.hassfest`.
- [x] New or updated dependencies have been added to `requirements_all.txt`.
Updated by running `python3 -m script.gen_requirements_all`.
- [x] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
- [x] Untested files have been added to `.coveragerc`.
The integration reached or maintains the following [Integration Quality Scale][quality-scale]:
<!--
The Integration Quality Scale scores an integration on the code quality
and user experience. Each level of the quality scale consists of a list
of requirements. We highly recommend getting your integration scored!
-->
- [x] No score or internal
- [ ] 🥈 Silver
- [ ] 🥇 Gold
- [ ] 🏆 Platinum
<!--
This project is very active and we have a high turnover of pull requests.
Unfortunately, the number of incoming pull requests is higher than what our
reviewers can review and merge so there is a long backlog of pull requests
waiting for review. You can help here!
By reviewing another pull request, you will help raise the code quality of
that pull request and the final review will be faster. This way the general
pace of pull request reviews will go up and your wait time will go down.
When picking a pull request to review, try to choose one that hasn't yet
been reviewed.
Thanks for helping out!
-->
To help with the load of incoming pull requests:
- [x] I have reviewed two other [open pull requests][prs] in this repository.
[prs]: https://github.com/home-assistant/core/pulls?q=is%3Aopen+is%3Apr+-author%3A%40me+-draft%3Atrue+-label%3Awaiting-for-upstream+sort%3Acreated-desc+review%3Anone+-status%3Afailure
<!--
Thank you for contributing <3
Below, some useful links you could explore:
-->
[dev-checklist]: https://developers.home-assistant.io/docs/en/development_checklist.html
[manifest-docs]: https://developers.home-assistant.io/docs/en/creating_integration_manifest.html
[quality-scale]: https://developers.home-assistant.io/docs/en/next/integration_quality_scale_index.html
[docs-repository]: https://github.com/home-assistant/home-assistant.io
opened 10:54AM - 28 Sep 20 UTC
closed 12:27PM - 10 Feb 21 UTC
integration: imap_email_content
stale
<!-- READ THIS FIRST:
- If you need additional help with this template, pleas… e refer to https://www.home-assistant.io/help/reporting_issues/
- Make sure you are running the latest version of Home Assistant before reporting an issue: https://github.com/home-assistant/core/releases
- Do not report issues for integrations if you are using custom components or integrations.
- Provide as many details as possible. Paste logs, configuration samples and code into the backticks.
DO NOT DELETE ANY TEXT from this template! Otherwise, your issue may be closed without comment.
-->
## The problem
<!--
Describe the issue you are experiencing here to communicate to the
maintainers. Tell us what you were trying to do and what happened.
-->
The sensor created by [imap_email_content](https://www.home-assistant.io/integrations/imap_email_content) changes its state to "unknown", also if there is email unread on the email inbox folder.
The imap_email_content works great when there is a new email.... but when I restart homeassistant after midnight automatically the state of the sensor change and become "unknown" until gmail receives a new different email.
I red:
[35975#](https://github.com/home-assistant/core/issues/35975#issue-623138819)
[36065#](https://github.com/home-assistant/core/pull/36065#issue-422378207)
## Environment
<!--
Provide details about the versions you are using, which helps us to reproduce
and find the issue quicker. Version information is found in the
Home Assistant frontend: Configuration -> Info.
-->
- Home Assistant Core release with the issue: 0.115.3
- Last working Home Assistant Core release (if known): I don't know. It's my first time that I use imap_email_content
- Operating environment (OS/Container/Supervised/Core): Linux 5.4.51-v7l+ virtualenv true Frontend: 20200918.2 python 3.7.3 Home Assistant 0.115.3
- Integration causing this issue: imap_email_content
- Link to integration documentation on our website: https://www.home-assistant.io/integrations/imap_email_content
## Problem-relevant `configuration.yaml`
<!--
An example configuration that caused the problem for you. Fill this out even
if it seems unimportant to you. Please be sure to remove personal information
like passwords, private URLs and other credentials.
-->
```yaml
sensor:
- platform: imap_email_content
server: imap.gmail.com
port: 993
username: !secret user_email
password: !secret password_email
senders:
- [email protected]
```
## Traceback/Error logs
<!--
If you come across any trace or error logs, please provide them.
-->
```txt
No error in the log
```
## Additional information
Sorry but I don’t understand if it's normal:
Imap_email_content gives me a sensor.XXXXXXXX where in the attribute body I can read my email content. Perfect.
But after midnight when I restart home assistant automaticanlly, the sensor become “unknown”. If I login in gmail I can see the email and the status “unread” so, why the component “Imap_email_content” can’t retriver it and it gives me “unknown”?
I read about to create another sensor template that change its state only if the sensor.XXXXX is not “unknown” but I’m not sure that when I restart homeassistant the new sensor can remember its old state.
My home assistant core version is: 0.115.3
I get a monthly email with a report… I need a sensor that continue to take the last report email also if I restart home assistant and automatically update when I recived a new email (which happens once a month).
Thanks for your feedback…
jampez77
(Jamie Nandhra-Pezone)
February 7, 2022, 3:49am
4
scan_interval isn’t a feature for this integration is it?
I’m having issues with this integration, along side what has been mentioned here.
thompy93
(Thomas)
February 7, 2022, 12:44pm
5
It is possible to set a scan_interval. I use 30 myself as a compromise between reducing traffic and in the same time get updates fast enough, as I use it with a camera.
The problem arise when you restart HA and it reads every unread email again as state.
Edit: i see now it is not mentioned in the docs. So not sure where I got it from. Put the project on ice for now anyways