Automation to/from home not working with WIFI SSID

Hi guys, I’m not very expert in hassio but by reading and searching in the community I tried to create an automation to turn the cameras on/off when one of the family members is at/from home using the zone and the WIFI SSID.
Using only the zone parameter the automation works correctly.
The problem is that by integrating the sensor that I created for each smartphone the automation does not work and does not turn the cameras on/off even if the sensor takes the correct home/non-home value for each smartphone based on the WIFI SSID.
I’ll send you the configuration files.
Can someone help me?
Thanks in advance

sensor.yaml

  • platform: template
    sensors:
    cellulare_m2007j3sy_home:
    unique_id: cellulare_m2007j3sy_home
    value_template: >-
    {% if states(‘sensor.cellulare_m2007j3sy_wifi_connection’) == “Home” or states(‘sensor.cellulare_m2007j3sy_wifi_connection’) == “Home-5G” %}
    home
    {% else %}
    not home
    {% endif %}
    friendly_name: ‘Cellulare M2007J3SY Home (SSID = Home)’
  • platform: template
    sensors:
    cellulare_m2007j3sy_home_2:
    unique_id: cellulare_m2007j3sy_home_2
    value_template: >-
    {% if states(‘sensor.cellulare_m2007j3sy_wifi_connection_2’) == “Home” or states(‘sensor.cellulare_m2007j3sy_wifi_connection_2’) == “Home-5G” %}
    home
    {% else %}
    not home
    {% endif %}
    friendly_name: ‘Cellulare M2007J3SY Home 2 (SSID = Home)’
  • platform: template
    sensors:
    cellulare_sm_a336b_home:
    unique_id: cellulare_sm_a336b_home
    value_template: >-
    {% if states(‘sensor.cellulare_sm_a336b_wifi_connection’) == “Home” or states(‘sensor.cellulare_sm_a336b_wifi_connection’) == “Home-5G” %}
    home
    {% else %}
    not home
    {% endif %}
    friendly_name: ‘Cellulare SM-A336B Home (SSID = Home)’
  • platform: template
    sensors:
    cellulare_m2007j20cg_home:
    unique_id: cellulare_m2007j20cg_home
    value_template: >-
    {% if states(‘sensor.cellulare_m2007j20cg_wifi_connection’) == “Home” or states(‘sensor.cellulare_m2007j20cg_wifi_connection’) == “Home-5G” %}
    home
    {% else %}
    not home
    {% endif %}
    friendly_name: ‘Cellulare M2007J20CG Home (SSID = Home)’

groups.yaml
famiglia:
name: famiglia
icon: mdi:home-heart
entities:
- device_tracker.cellulare_m2007j3sy
- device_tracker.cellulare_m2007j3sy_2
- device_tracker.cellulare_sm_a336b
- device_tracker.cellulare_m2007j20cg
- sensor.cellulare_m2007j3sy_home
- sensor.cellulare_m2007j3sy_home_2
- sensor.cellulare_sm_a336b_home
- sensor.cellulare_m2007j20cg_home

automations.yaml

  • id: ‘1682530973040’
    alias: Siamo in casa
    description: Se uno di famiglia è in casa disattiva le telecamere
    trigger:
    • platform: state
      entity_id:
      • group.famiglia
        to: home
        condition: []
        action:
    • type: turn_off
      device_id: 1e4720480958a6f5de12a2f1cb67b947
      entity_id: switch.sonoff_10005e0f93
      domain: switch
    • type: turn_off
      device_id: 4eae1bc18820531c6fe68eda488aa181
      entity_id: 10e14b9c3224263362d0dbce4b6a676e
      domain: switch
      initial_state: ‘true’
      mode: single
  • id: ‘1682531097600’
    alias: Siamo fuori casa
    description: Se siamo tutti fuori casa attiva le telecamere
    trigger:
    • platform: state
      entity_id: group.famiglia
      from: home
      condition: []
      action:
    • type: turn_on
      device_id: 1e4720480958a6f5de12a2f1cb67b947
      entity_id: switch.sonoff_10005e0f93
      domain: switch
    • type: turn_on
      device_id: 4eae1bc18820531c6fe68eda488aa181
      entity_id: 10e14b9c3224263362d0dbce4b6a676e
      domain: switch
      initial_state: true
      mode: single
  • id: ‘1682616564293’
    alias: Entrata
    description: Se uno di famiglia è in casa disattiva le telecamere
    trigger:
    • platform: numeric_state
      entity_id: zone.home
      above: 0
      condition: []
      action:
    • type: turn_off
      device_id: 1e4720480958a6f5de12a2f1cb67b947
      entity_id: switch.sonoff_10005e0f93
      domain: switch
    • type: turn_off
      device_id: 4eae1bc18820531c6fe68eda488aa181
      entity_id: 10e14b9c3224263362d0dbce4b6a676e
      domain: switch
      initial_state: ‘true’
      mode: single
  • id: ‘1682616277552’
    alias: Uscita
    description: Se siamo tutti fuori casa attiva le telecamere
    trigger:
    • platform: numeric_state
      entity_id: zone.home
      below: 1
      condition: []
      action:
    • type: turn_on
      device_id: 1e4720480958a6f5de12a2f1cb67b947
      entity_id: switch.sonoff_10005e0f93
      domain: switch
    • type: turn_on
      device_id: 4eae1bc18820531c6fe68eda488aa181
      entity_id: 10e14b9c3224263362d0dbce4b6a676e
      domain: switch
      initial_state: ‘true’
      mode: single

Why not just use the mobile app as the device tracker.

I use this automation to turn on/off my heating when someone is in the house, or when everyone leaves the house and it also sends me a push notification:

alias: Set Tado Home or Away
description: ""
trigger:
  - platform: state
    entity_id:
      - zone.home
condition: []
action:
  - if:
      - condition: numeric_state
        entity_id: zone.home
        below: 1
      - condition: state
        entity_id: climate.main_house
        attribute: preset_mode
        state: home
    then:
      - service: notify.mobile_app_xxxxx
        data:
          message: Away Mode Activated
          title: Tado Alert
      - service: script.set_tado_mode_away_and_reset
        data: {}
    else:
      - if:
          - condition: numeric_state
            entity_id: zone.home
            above: 0
          - condition: state
            entity_id: climate.main_house
            attribute: preset_mode
            state: away
        then:
          - service: notify.mobile_app_ro_p30_pro
            data:
              message: Home Mode Activated
              title: Tado Alert
          - service: script.set_tado_mode_home_and_reset
            data: {}
mode: single

Agreed with Ro. Why aren’t you just using the count of the home zone? Even if you want to use those phones. Just make sure they’re all assigned as device trackers to each appropriate person and the zone count will include the calculation and you don’t have to build an automation to handle it.

Thanks for the reply. How can I assign the sensor as device trackers to each smartphone? The problem is that if you live in a building on the 6th floor the zone always considers you to be at home even if you are in the garden or on the first floor visiting a friend; thus the detection of the WIFI SSID becomes more precise.

The problem is that if you live in a building on the 6th floor the zone always considers you to be at home even if you are in the garden or on the first floor visiting a friend; thus the detection of the WIFI SSID becomes more precise.