How to NOT trigger an action?

I do not quite understand your objectives either, but…

Just an idea and don’t know if this helps, but specifically for NOT running an action, after initial triggers / conditions of the automation…

Instead of adding actions (to run the dinner2tv script, for example), you can add building blocks:
image

… and then, maybe use one of those to check whether conditions are or are not met, before proceed to your dinner2tv script.

The trick is probably going to figure out some other conditions to check, to decide whether the automation would proceed or ignore the action…

Again, my 2 cents.

The main objective is

a) to trigger an action when the charger_type changes to ‘wireless’ because the tablet has been placed into the dock

but

b) to NOT trigger the action when the charger_type changes to ‘wireless’ because the tablet-internal charging mechanism turned off and back on within 15 seconds

and

c) to NOT trigger the action when the charger_type changes to ‘wireless’ because the smart plug device (entity_id switch.mplug) has been turned on

I have a) and b) sorted out and looking for a solution for c).

And:
Correct, I’m looking for a condition without a massive workaround with helpers, etc., that can tell me, if a switch has changed its state from off to on in the last 15s.

Spoiler:

Sorry if I have misunderstood, but maybe you can get something out of a combination of what you have together with the following?

The switch should be on:
is_state('switch.mplug', 'on')
and
it should have been on for more than 15 seconds
now() - states.switch.mplug.last_changed > timedelta(seconds=15)
right?

Edit: See also State and state object - Home Assistant

Thanks, @luxia

That’s what I was looking for - I thought there must be a way, but I couldn’t get it right :frowning:

Now I only need to figure out how to run this when I’m placing the tablet in the dock and switch.mplug is off - or to just turn on switch.mplug after the tablet has been removed for more than 15s.

How about this:

You still use this as the trigger of the automation.

And the conditions of the automation could stay the same as the same conditions of what’s in your OP (or not if you think that is irreverent)

And let’s add building block If-then instead of adding any action.
Under the “if” of the forementioned If-then block, you do another logic block And to check both of these being true:

… assuming you have figured out the logic for c)

and then, under the “then” of the forementioned if-then logic block, you include your action.

= = = =
If something is still not working, post where you are / your latest attempt of the automation. People might ask you further questions of “what is the state of this entity”, “test this in template under Developer Tools”, or “what is the make/model of the smart plug”, etc… but please post your latest yaml.

This is what I have right now:

alias: DRDash Wireless Charging Triggers Dinner2TV
description: ""
triggers:
  - trigger: state
    entity_id:
      - sensor.drdashboard_charger_type
    to:
      - wireless
conditions:
  - condition: time
    after: "19:45:00"
  - condition: template
    value_template: >-
      {% set previous = trigger.from_state.last_changed | as_datetime | as_local %}
      {{ now() - previous > timedelta(seconds=15) }}
  - condition: template
    value_template: |
      {{ now() - states.switch.mplug.last_changed > timedelta(seconds=15) }}
actions:
  - data:
      message: TTS
      data:
        tts_text: The Dining Room Dashboard is now back in the charging cradle
        media_stream: alarm_stream
        priority: high
    action: notify.mobile_app_drdashboard
  - action: script.dinner2tv
    metadata: {}
    data: {}
    enabled: false
mode: single

It works for b) and c) as well as for a) as long as the wall wart/charger is on.

I does not work for a) after the tablet charge previously reached 80%, has been turned off due to that and the charge is still north of 50%, i.e. the wall wart has not turned back on yet and therefore the charger_type does NOT change to ‘wireless’.
Obviously, in this case it’s the trigger that doesn’t work.

I’d need to find a way to discover that tablet has been removed from the dock even if the wall wart is off and then turn it on so that my trigger works again.

Once the wall wart, i.e. switch.mplug is off, maybe I can check every 5min if turning it on changes the charger_type to wireless.

  • If the charger_type does not change to wireless, it means that the tablet is not in the charger and I keep it on.
  • If the charger_type does change to wireless, it means that the tablet is in the charger and I turn it back off.

One of my favourite phrases is: There’s always a hardware solution to a software problem.

Stick a tiny magnet to the back of your tablet. Stick a tiny door/window sensor to your Fire tablet stand.

No helpers required, just an additional condition in your automations to detect if your tablet is docked or not. If the sensor isn’t reporting as closed, then it’s not docked.

I thought about that, but I love myself a challenge. :wink:

And the door/window sensor I have at hand is too bulky, and it’s WiFi, and it’s a Tuya one :frowning:

Get a zigbee one. The old Aqara ones are exceptionally cheap & tiny (even more so of you extract the board from the plastic case).

Search these forums for Aqara hacks - you’ll be pleasantly surprised.

I know - I have a few of these, but just not at hand right now.

And then there’s the SPAF :wink:
Sticking a contact sensor on the tablet dock is not going to go down well.

I’ve disassembled a few since way back when:
How I made my dumb locks a little smarter! - Share your Projects! - Home Assistant Community

Appreciate the suggestions, though!

if your tablet can do NFCs, maybe an RFID tag / sticker with clever placement would help.

2 Likes

Can you just add a trigger to turn on the smart switch when your Spotify page comes up? That would ensure you have power on the charger when you cradle it.

It’s been a while since I worked with a Fire Tablet, but assuming it is in a static position while in the cradle you could use a motion or angle sensor in the tablet if it’s exposed to then turn on the smart switch.

Short of that, if you have a normal time frame on when you use the tablet and put it back you could hard code a time when the switch should turn on.

1 Like

Unfortunately, the tablet doesn’t do NFC :frowning:

I like the idea!

Unfortunately, the dashboard on the tablet currently automatically changes to a (Spotify) Media Player card (in full screen) when I start streaming music to my Google Chromecast Audios, no matter where the tablet is. So, this would probably create a lot of false positives for the trigger.

Quick update on what I ended up doing:

To ensure that the charger is on and I can detect that the tablet has been replaced into the dock, I’m running an automation every 5min.
The automation first checks, if the charger is already in order to not run the other checks and actions unnecessarily.

It then turns on the smart plug.

If the charger_type changes to wireless withing 5 seconds, it means that the tablet is in the charger and that the smart plug was switched off because the tablet entered its discharge cycle.
=> The smart plug will switch itself off again to allow the tablet to discharge further.

If the charger_type doesn’t change to wireless, it means that the tablet is NOT in the charger.
=> The smart plug will stay switched on so that I can detect when the tablet is replaced into the charger and I can trigger the automation that sets up my TV Den for watching TV.

This setup should also still work fine with the complication mentioned above:

By stopping the charger at 80% the complication should actually never come into play, but I just want to make sure I avoid sitting in the dark in the middle of dinner while the TV turns on :stuck_out_tongue:

1 Like