So… I am at a complete loss at the moment. I have spent 2 days buried in all the IMAP, template, YAML, forum articles and documentation. I feel like the “only” ping pong ball at a Olympic table tennis tournament. I was trying to be respectful to all the forum users, by RTFM standards, but I’m just mush now.
I have a technical background, but I’m not a long-time user of HA or deep home automation stuff. I’ve just integrated some stuff like Hue lights, Ubiquiti stuff, Hubspace outlet, just to do simple stuff.
My goal is to use HA to turn on/off a hubspace outlet, which in turn controls the charging of my laptop, based on battery charge percentage.
My battery recently swelled, and HP warranty replaced it, as a “courtesy”. But they felt I didn’t have enough charge cycles (which was true… it stays plugged all the time). I didn’t want to manually charge/discharge, so I wrote a small shell script that uses upower to get the charge percentage. I then use monit, to monitor that output, and pass to M/monit, which sends emails. With this, I can cycle my hubspace outlet when mail hits the inbox. I have the IMAP integration setup (which just monitors a state change). That’s all well and good.
The email content I’m interested in contains the following important info:
‘status failed (24)’ - would turn on the Hubspace outlet and start charging.
‘status succeeded (95)’ - would turn off the Hubspace outlet and stop charging.
I finally, today, figured out the theory of setting up a “helper”, but I cannot figure out how to link that to my IMAP entity. I see them, I just don’t know what to do next… how to link or use the helper/template.
In my configuration.yaml I added a line
template: !include templates.yaml
I created a templates.yaml and I added this (which I hijacked out of a forum article)
trigger:
- platform: event
event_type: "imap_content"
id: "haos_mail_eventid"
event_data:
sender: haos@<mydomain>.com
sensor:
- name: haos_mail_sensor
state: "{{ trigger.event.data['subject'] }}"
attributes:
Message: "{{ trigger.event.data['text'] }}"
Server: "{{ trigger.event.data['server'] }}"
Username: "{{ trigger.event.data['username'] }}"
Search: "{{ trigger.event.data['search'] }}"
Folder: "{{ trigger.event.data['folder'] }}"
Sender: "{{ trigger.event.data['sender'] }}"
Date: "{{ trigger.event.data['date'] }}"
Subject: "{{ trigger.event.data['subject'] }}"
My automations,yaml has this for my basic toggle, which ia working presently
- id: '1730813515451'
alias: Toggle outlet on alert email
description: ''
triggers:
- trigger: state
entity_id:
- sensor.imap_haos_<mydomain>_com
conditions: []
actions:
- type: toggle
device_id: 68f140d806c70697b61283f621cd3531
entity_id: eea9c9fb
Somewhere I tried this, though I can’t remember where… anyway, it contains the strings I’m trying to look for in the emails. It may need to be part of the above template, IDK.
template:
- trigger:
- platform: event
event_type: "imap_content"
id: "custom_event"
event_data:
sender: "notify@<mydomain>.com"
initial: true
sensor:
- name: "OutletTriggerEmail"
state: >-
{% if 'status failed (24)' in trigger.event.data["body"] %}
OutletOn
{% elif 'status succeeded (95)' in trigger.event.data["body"] %}
OutletOff
{% endif %}
Anyway, thanks for listening, and if you pointers, Thank You in advanced!