Automation with notification is not firing

Hi,

I am working on a way to check if there is anything in my mailbox. I want the use what is called a latching power switch circuit - see more here (https://randomnerdtutorials.com/latching-power-switch-circuit-auto-power-off-circuit-esp32-esp8266-arduino/) for those interested, really a fantastic thing that uses almost no power, years and years on battery, longer than deep sleep.

So, I have made the ESP code. It seems to be working. I have made both a switch and a binary sensor, just as part of testing as I could not get the automation (see further down) to work and thought perhaps that had something to do with it.

And I am so sorry about the formatting. It comes out a bit strange even if I use ´´´, and I tried to copy it first into Notepad++ to see if that made a difference, seems not… EDIT: Got it, needed the backtick.

esphome:
  name: postkasse
  platform: ESP8266
  board: nodemcuv2
  on_boot:
    then:
       switch.turn_on: generic_out_swith
    
wifi:
  ssid: "xxxx"
  password: "xxxx”

captive_portal:

logger:

api:

ota:

output:
 - platform: gpio
   id: generic_out
   pin: D8

switch:
 - platform: gpio
   pin: D8
   name: Generic_Output
   id: generic_out_swith
   restore_mode: ALWAYS_ON
   
binary_sensor:
  - platform: gpio
    pin: 
      number: D2
      mode: INPUT_PULLUP
    name: dererpost

So, the above is all fine, both Generic_Output and dererpost switches on when the nodemcu is power up. I can see they are on in lovelace and in the log.

Now, here is the automation that I can not get to work, no matter if I try with Generic_Output or dererpost. I simply do not get a notification. It works fine if I press Execute (the reason why I switch of the switch is to unlatch the power circuit so the ESP goes back to sleep). Any takes on why I do not get a notification if Generic_Output or dererpost are on?

- id: '1590151128548'
  alias: notify when mail
  description: ''
  trigger:
  - device_id: 6ae55cdb0f534d9e9139f5d6c2f44cf5
    domain: binary_sensor
    entity_id: binary_sensor.dererpost
    platform: device
    type: turned_on
  condition: []
  action:
  - data:
      message: Der er post
    service: notify.mobile_app_mi_mix_2
  - device_id: 6ae55cdb0f534d9e9139f5d6c2f44cf5
    domain: switch
    entity_id: switch.generic_output
    type: turn_off

Please read the forum guidelines and format your code correctly.
Do you get any errors in the log? Does the notify seevice work when you exwcute it manually via Developer Tools -> Services?

Wrong character. It’s the backtick you want.

Sorry, I see from Troon that I used the wrong tick, is corrected now. Thanks Troon.

The notification fires fine when I execute the automation manually, so that is not the problem. The problem, is, I assume, somehow related to the automation not seeing the change in the switch or the binary sensor. And, no I no errors in the logbook (assuming that is what you talk about), only that they switch and the binary sensor have been turned on.

A binary sensor does not have a state turned_on, is either on or off. Check the docs

No, I’m talking about Developer Tools → Logs. The logbook “only” shows what happened to sour entities, no errors or such things.

@sjee found the issue in your automation. Change your trigger to:

trigger:
  platform: state
  entity_id: binary_sensor.dererpost
  to: 'on'

Check the docs here for more details.

Thanks a zillion. It works. Once again it was something simple. My problem is I still have not quite grasped the differences between a switch and a binary sensor, and most less about what is turned on and of, what has a state etc. But if the short version is that a binary sensor only senses, eg. has a state, then I do not understand why it did not work when I used the switch Generic_Output in the automation. Anyhow, as long this works I am happy. Thanks again.

A binary sensor can have a state of either ‘on’ or ‘off’, but you can’t turn it on/off.
A switch can have a state of either ‘on’ and ‘off’ AND you can turn it on/off.

The action part of your automation was correct just the trigger was wrong.

1 Like