Automation are sensor does not work

Hello everyone. Could someone tell me if they see something wrong with this automation. I would think it’s ok but I can’t find the problem. The motion sensor is zigbee and is controlled by zigbee2mqtt. The sensor states are false and true. I tried with those states and with on off and in no case did it work.

  - alias: "Enciende pasillo cuando entras al pasillo de noche"
    id: "12365745523"
    mode: parallel
    trigger:
      platform: state
      entity_id:
        - sensor.sensor_pasillo_occupancy
      from: 'off'
      to: 'on'
    condition:
      - condition: and
        conditions:
          - condition: state
            entity_id: light.comedor
            state: "off"
          - condition: state
            entity_id: light.pasillo
            state: "off"
          - condition: state
            entity_id: sun.sun
            state: "below_horizon"
    action:
      - service: light.turn_on
        target:
          entity_id: light.pasillo 
      - delay:
          seconds: 10
      - service: light.turn_off
        target:
          entity_id: light.pasillo

In that case, isn’t this a binary sensor? Try:

entity_id:
        - binary_sensor.sensor_pasillo_occupancy

All my motion sensors are binary - ‘off’ and ‘on’ should be OK.

Also, multiple conditions are always ‘and’, so I think that section could be something like:

  condition:
  - condition: state
    entity_id: light.comedor
    state: 'off'
  - condition: state
    entity_id: light.pasillo
    state: 'off'
  - condition: state
    entity_id: sun.sun
    state: below_horizon

It is actually a mqtt sensor that has a json with all the attributes in its state.

To get the values ​​I did this

mqtt:
  sensor:
    - name: movimiento-pasillo
      state_topic: zigbee2mqtt/Sensor movimiento pasillo   
    - name: Sensor Pasillo - Illuminance
      state_topic: zigbee2mqtt/Sensor movimiento pasillo   
      unit_of_measurement: "lx"
      value_template: "{{ value_json.illuminance }}"
    - name: Sensor Pasillo - Occupancy
      state_topic: zigbee2mqtt/Sensor movimiento pasillo   
      value_template: "{{ value_json.occupancy }}"           
    - name: Sensor Pasillo - Battery
      state_topic: zigbee2mqtt/Sensor movimiento pasillo   
      unit_of_measurement: "%"
      value_template: "{{ value_json.battery }}"    

It is not a sensor but an attribute of the sensor. It does not have it as a state

It should be a binary sensor if it only has two states.

mqtt:
  binary_sensor:
    - name: Sensor Pasillo - Occupancy
      state_topic: zigbee2mqtt/Sensor movimiento pasillo   
      device_class: occupancy
      value_template: "{{ value_json.occupancy }}" 

Then change your trigger to:

  - alias: "Enciende pasillo cuando entras al pasillo de noche"
    id: "12365745523"
    mode: parallel
    trigger:
      platform: state
      entity_id:
        - binary_sensor.sensor_pasillo_occupancy
      from: 'off'
      to: 'on'

If you don’t want to change to a binary sensor for some reason just change your trigger to:

  - alias: "Enciende pasillo cuando entras al pasillo de noche"
    id: "12365745523"
    mode: parallel
    trigger:
      platform: state
      entity_id:
        - sensor.sensor_pasillo_occupancy
      from: 'false'
      to: 'true'

Also FYI when choosing a forum category:

Configuration: anything about configuring home assistant integrations, automations or scripts.
Configuration - Frontend: anything about configuring dashboards and cards.

Hello. Tried to create the binary entity and it says unknown. The sensor type entity detects between true and false when it happened but the automation is never triggered. I keep trying things but I don’t know where the problem is

By default, MQTT Binary Sensor expects to receive ON and OFF in order to report on/off (unlike a Template Binary Sensor which accepts a broader range of ‘truthy/falsey’ values by default)

In your example, either change the default values to true/false

mqtt:
  binary_sensor:
    - name: Sensor Pasillo - Occupancy
      state_topic: zigbee2mqtt/Sensor movimiento pasillo   
      device_class: occupancy
      value_template: "{{ value_json.occupancy }}"
      payload_on: true
      payload_off: false

Or modify the template:

      value_template: "{{ iif(value_json.occupancy, 'ON', 'OFF') }}" 

It worked. Thank you very much for the help. Now I am going to see why in low light it does not activate but it is another problem.