Correct "Conditions" for AND NOT

Hey all –

Question on the correct setup for using an AND and a NOT. This is what I’m trying to achieve in the logic (sensor names paraphrased for simplicity)

(jp16 NOT home) AND (mrs_ps NOT home)

Here is the screenshot how I have it configured:

Is this the correct what to do a (jp16 !home) and (mrs_ps !home)?

It looks right to me, I just didn’t want to assume it was right.

Thanks,

-Alli

The capitals are a problem and the opposite of ‘home’ is ‘away’

Here is one of my templates : -

          {% set dist = states('sensor.s_occupancy_muttley_dist') | float %}
          {% if dist > states('input_number.in_occupancy_near_heat') | float %}
            Away
          {% elif dist > states('input_number.in_occupancy_near_light') | float %}
            Heat
          {% elif dist > states('input_number.in_occupancy_near_sound') | float %}
            Light
          {% elif not is_state('device_tracker.life360_muttley', 'home') %}
            Announce
          {% elif is_state('device_tracker.life360_muttley', 'home') %}
            Home
          {% else %}
            Home
          {% endif %}

This sensor sets whether the heating is on, the lights are allowed on or both

Here is the yaml that it created:
Screen Shot 2020-12-24 at 9.23.11 AM

While I can code, I try to use the UI in every case that I can so I can support it at that level (so more people can adopt it).

Based on the yaml that it created, it looks right to me… Just wanted to confirm.

The advantage of using NOT “home” is that it will work when you have other zones set up. (In my case, I have seven and the sensors only read “not_home” when we’re not in any of those zones.)
I use a group with my (three) presence sensors. If any of the entities is home then the group will read home/on, but if all of them are not_home, it will read off/not_home.

2 Likes

True !

But Alli is not using device_tracker’s he’s using special sensors set up determine the ‘name’ of the zone the ‘persons’ are in.
Using the built in functionality of device trackers or person would mean a simpler and much wider user base

If he is are ‘paraphrasing’ the sensors from device_tracker’s or person’s then he is confusing his potential user base too

Also pasting that image is a much bigger post (size on server etc) than the text, and people comming to it can’t copy and paste the text to see individual states (template editor)

Well, they are device trackers… These are the recommended way to track a device when you’re using the add-on called iCloud3. It works really well and in the docs, using the appropriate *_zone_name is what will give the best representation of whether the device is home or not. Sounds like I’ve got it set up right in the UI - thanks for the replies. :slight_smile:

For future reference, what Mutt is referring to is copying the code and pasting it into the text of your post. To do that, you also need to put three back quotes (like this ```) on the line before you paste it and on the line after you paste it. If would look like this:

condition: and
conditions:
  - condition: not
    conditions:
      - condition: state
        entity_id: sensor.mrs_ps_iphone_zone_name
        state: Home
      - condition: state
        entity_id: sensor.jp16_iphone_zone_name
        state: Home

Since that’s text, it makes the post load faster (on slow connections) and allows other to copy and paste as Mutt suggests.

1 Like

Thanks, my router is currently acting up and I’m under pressure from family members to get it fixed, like yesterday. :+1:

I guess it depends on if this truly is a custom sensor that the OP created but just for clarification, the usual states are “home” & “not_home” not “home” & “away”. And you are correct about the capitalization. It always needs to match the state as seen in the dev tools → states page.

1 Like

I stand corrected (I should really check these things before making trump like announcements)
Ive never heard of his addon (not sure why you’d need an addon for something that is inherent in the standard installation) but it seems to be configured to produce ‘Home’ - dunno !

Edit: but as @qoheleth correctly pointed out not home was the desired state to test

2 Likes

Here is the page for icloud3 if anyone is interested: https://github.com/gcobb321/icloud3

Here is a couple screenshots of the datapoints that it bring to the table. What I like about it most is that the closer you get to a zone, the more it updates so the end result is that it’s really accurate and it only uses what the phones use already with an iCloud account and the HA app. Some fields are replicated as they’re transitioning to new ones. What is also cool is the time to home as well that is calculated by Waze.