Trying to use Ambient weather and the rain state... little help with sensor state?

I just switched to NWS. I’m still learning what I can do with it, but for now, I think my ambient weather station can be used. I have an entity called
sensor.weatherstation_event_rain
The state is 0 with no rain, and it changes by decimal. So at the very first start of rain, it changes to 0.123 (I think 3 dec places.)
What I’m asking is, what code could I use to replace the following automation -

- alias: "Alert for open windows when raining"
  trigger:
    - platform: state
      entity_id: sensor.weatherstation_event_rain
      to: "rainy"
  condition:
    - condition: time
      after: "6:00"
      before: "23:00"
  state_attr('group.windows', 'entity_id'))|list)|groupby('state'))['on']|map(attribute='name')|list|join(', ') }} is opened."
    - service: notify.mobile_app_pixel_5
      data_template:
        message: "It is raining and the {{ dict((states | selectattr('entity_id', 'in', state_attr('group.windows', 'entity_id')) | list) | groupby('state'))['on'] | map(attribute='name') | list | join(', ') }} is opened."

I know that the code is wrong for rainy, and unfortunately I don’t know much about templates, but was wondering how I could trigger the automation if the value is above 0.1 or, do I need to change the state to rainy.
Thanks!

  trigger:
    - platform: numeric_state
      entity_id: sensor.weatherstation_event_rain
      above: 0

Link to numeric_state trigger examples:

Awesome! Thanks!

Just what I needed for my Ambient weather station.
First off can you explain what the state_attr statement is being used for. I just get errors.
Second have you created any other automations for the station.
Thanks @SandmanXX

Well Carlton, this code doesn’t work for me yet. I’ve picked it up off the forums here, under config somewhere, it does NOT display which window(s) is/are open. I’m still looking around, I’m in the early stages of learning this myself. I can cut and paste, and understand a little, and get a little adventurous as well :slight_smile:
That statement is supposed to display which windows, which I have grouped in groups yaml, are showing open, once the weatherstation shows .1+ inches of rain. I get the notification, it’s just and empty one, so it works halfway. I get something like " It is raining and the is opened." So, until I find out how to get the windows listed… I really don’t know enough about templates and statements right now to help much more.
I can see many possibilities for using the AWS for things, I made a entity lovelace card for every single entity it gives from developers console, just to see what I can do. Very early stages yet.
If I hear how to fix this listing, I’ll update here.
here’s the thread I found this in -
Automation to alert specific open windows when it is raining? - Configuration - Home Assistant Community (home-assistant.io)

Yes, this code isn’t listing the windows. Setting states in dev, and running the actions, I only get “It is raining and the window is open”. Here’s the current code I’m trying to run -

- alias: "Alert for open windows when raining"
  trigger:
    - platform: numeric_state
      entity_id: sensor.grover_nc_weather_station_event_rain
      above: 0
  condition:
    - condition: time
      after: "6:00"
      before: "23:00"
  action:
     - service: notify.mobile_app_pixel_5
      data_template:
        message: >
          {% set w = expand('group.windows') | selectattr('state', 'eq', 'on') | map(attribute='name') | list %}
          It is raining and the {{ w | join(', ') }} window{{ 's are' if w | count > 1 else ' is' }} open.

Ok, so far experimenting, if -2- windows are open, it lists ONE window, by sensor name, as being open. Going to keep working on this.

This code will list ONE window open, if more are opened it still only lists one, I’m assuming the window being opened the longest by history, based on when I changed state :slight_smile:

message: "It is raining and the {{ expand('group.windows') | selectattr('state', 'eq', 'on') | map(attribute='name') | list | join(', ') }} is opened."

First, thank you for the reply.
Let’s see if I can point you in a direction that might give you a hint.

I use alarm.com for my hard wired alarm system. HA has some integrations and such so I took advantage of it.
I first created a binary sensor to look like this.

####################################################
  alarm_14_office_window:
    friendly_name: "14_Office Window"
    device_class: window
    value_template: "{{ state_attr('alarm_control_panel.alarm_com', 'sensor_status')|regex_search('14_Office Window is Open', ignorecase=TRUE) }}"

I then created some groups that look like this.

####################################################
#            GROUP.WINDOWS                         #
####################################################
windows:
  entities:
    - binary_sensor.alarm_5_master_bedroom_window_1
    - binary_sensor.alarm_6_master_bedroom_window_2
    - binary_sensor.alarm_7_master_bathroom_window
    - binary_sensor.alarm_9_greatroom_window_1
    - binary_sensor.alarm_10_greatroom_window_2
    - binary_sensor.alarm_12_kitchen_window
    - binary_sensor.alarm_13_bedroom_window
    - binary_sensor.alarm_14_office_window
####################################################
#           GROUP.DOORS                            #
####################################################
doors:
  entities:
    - binary_sensor.alarm_1_frontdoor
    - binary_sensor.alarm_4_garage_door_inside
    - binary_sensor.alarm_11_greatroom_french_doors
####################################################   

Lastly I create an automation that tells me when a door or window is opened/closed.

####################################################
#         DOOR WINDOW STATUS       2020Apr07                        #
####################################################
- alias: Door and Window Monitor
  mode: queued
  trigger:
    - platform: state
      entity_id:
        - binary_sensor.alarm_5_master_bedroom_window_1
        - binary_sensor.alarm_6_master_bedroom_window_2
        - binary_sensor.alarm_7_master_bathroom_window
        - binary_sensor.alarm_9_greatroom_window_1
        - binary_sensor.alarm_10_greatroom_window_2
        - binary_sensor.alarm_12_kitchen_window
        - binary_sensor.alarm_13_bedroom_window
        - binary_sensor.alarm_14_office_window
        - binary_sensor.alarm_1_frontdoor
        - binary_sensor.alarm_4_garage_door_inside
        - binary_sensor.alarm_11_greatroom_french_doors
  action:
    - service: notify.telegram_carlton
      data:
        title: Alert
        message: The {{ trigger.to_state.name }} was {{ 'opened' if trigger.to_state.state == 'on' else 'closed' }}

Lastly I made an automation that told me what door/windows were open at 8 pm.

####################################################
#              DOORS OPEN STATUS   2020Apr02                          #
####################################################
#https://community.home-assistant.io/t/automation-that-checks-for-is-doors-are-open-before-going-to-bed/59456/7
- id: "1793401787732"
  alias: "8 pm Door Check"
  description: Door Check
  trigger:
    - at: "19:59:00"
      platform: time
  condition:
    condition: template
    value_template: >
      {{ states | selectattr('entity_id', 'in', state_attr('group.doors','entity_id')) | selectattr('state','in',['on','open']) | list | length >= 1 }}
  action:
    - service: media_player.volume_set
      data:
        volume_level: 0.7
      entity_id: media_player.everywhere
    - data:
        entity_id: group.echo
        media_content_id: amzn_sfx_trumpet_bugle_04
        media_content_type: sound
      service: media_player.play_media
    - data:
        data:
          method: speak
          type: announce
        message: >
          {% set open_doors = ( states | selectattr('entity_id', 'in', state_attr('group.doors','entity_id')) | selectattr('state','in',['on','open']) | list | map(attribute='name') | join(', ') ) %}
            It is 8 pm and the following doors are open: {{ open_doors }}
      service: notify.alexa_media_everywhere
    - service: notify.telegram_carlton
      data_template:
        title: "It's 8 PM Doors Open!"
        message: >
          {% set open_doors = ( states | selectattr('entity_id', 'in', state_attr('group.doors','entity_id')) | selectattr('state','in',['on','open']) | list | map(attribute='name') | join(', ') ) %}
            Its 8 PM and the following doors are open: {{ open_doors }}
  mode: single
####################################################
#          WINDOW OPEN STATUS      2020Apr02                        #
####################################################
#https://community.home-assistant.io/t/automation-that-checks-for-is-doors-are-open-before-going-to-bed/59456/7
- id: "1893401787732"
  alias: "8 pm Window Check"
  description: Window Check
  trigger:
    - at: "19:58:00"
      platform: time
  condition:
    condition: template
    value_template: >
      {{ states | selectattr('entity_id', 'in', state_attr('group.windows','entity_id')) | selectattr('state','in',['on','open']) | list | length >= 1 }}
  action:
    - service: media_player.volume_set
      data:
        volume_level: 0.8
      entity_id: media_player.everywhere
    - data:
        entity_id: group.echo
        media_content_id: amzn_sfx_trumpet_bugle_04
        media_content_type: sound
      service: media_player.play_media
    - data:
        data:
          method: speak
          type: announce
        message: >
          {% set open_windows = ( states | selectattr('entity_id', 'in', state_attr('group.windows','entity_id')) | selectattr('state','in',['on','open']) | list | map(attribute='name') | join(', ') ) %}
            It is 8 pm and the following windows are open: {{ open_windows }}
      service: notify.alexa_media_everywhere
    - service: notify.telegram_carlton
      data_template:
        title: "It's 8 PM Windows Open!"
        message: >
          {% set open_windows = ( states | selectattr('entity_id', 'in', state_attr('group.windows','entity_id')) | selectattr('state','in',['on','open']) | list | map(attribute='name') | join(', ') ) %}
            Its 8 PM and the following windows are open: {{ open_windows }}
  mode: single
####################################################
#            END OF CONFIGURATION FILE             #
####################################################

All of the automations work well.
Last night I created your automation. I opened a window, then sprayed the weather station with some water. Within 30 seconds I got a notice informing me it was raining and my office window was open.
So for me it worked.

Maybe you can kludge something together from this information!

This template starts by casting a really wide net (all entities) then whittles it down to just the entities in the group.

    value_template: >
      {{ states | selectattr('entity_id', 'in', state_attr('group.doors','entity_id')) | selectattr('state','in',['on','open']) | list | length >= 1 }}
 

I suggest just using the group’s entities from the start.

    value_template: >
      {{ expand('group.doors') | selectattr('state','eq','on') | list | length >= 1 }}
 

Your group.doors contains only binary_sensors whose state value is either on or off (never open). So there’s no need to check for either on or open. “Open” is displayed in the UI if the binary_sensor’s device_class is door (but is not its state value).

Thanks @123, never caught that.

Still slowly piddling around with this. Been sick past couple weeks, tested neg twice, but still symptoms. Oh well. Work goes on also :slight_smile:
I may have figured out one thing, I didn’t realize that one out of 10ish so far window sensors is a multi v4 switch from ST, forgot about it, but it shows off, where all others show closed, in lovelace. The dev console says it reports off just like the rest of my sensors, which are now all linkind or centralite (these are working GREAT) but yet in lovelace and in device page that entity shows ‘off’.
Dunno, going to replace it this weekend with freshly ordered linkind window sensors to join the rest, No idea it that may or may not be doing to something.

And come to find out, the weather sensor has gone a bit bad. Ordered a new one (same) to replace, should be here monday. That’s one reason I think I had the problem of rain getting stuck as having some where there was none. :frowning: