Multiple sensors control a device

Hi!
I would like to control 1 relay with 4 xiaomi opening sensors.
“if you open a sensor then open the relay too, if all sensors are closed then close the relay as well”
how can i automate this. thanks

Show us what you have done so far.
and we love to help
ie

Your Automation, script there ID’s

Add all your sensor to a group.

Automation:

trigger:
  platform: state
  entity_id: group.your_sensor_group_here
action:
  service_template: "{{ switch.turn_on if is_state('trigger.to_state', 'on') else switch.turn_off }}"
  entity_id: switch.your_relay_here

Thanks! I’m studying homeassistant now.
What have I done wrong?

  alias: relay3
  description: ''
  trigger:
  - entity_id: group.windows
    platform: state
    to: 'off'
  condition: []
  action:
  - condition: template
    value_template: 'service_template: "{{ switch.turn_on if is_state(''trigger.to_state'',
      ''on'') else switch.turn_off }}"'
  - data: {}
    entity_id: switch.relay3
    service: switch.turn_off

This is all you need:

  alias: relay3
  trigger:
    platform: state
    entity_id: group.windows
  action:
    service_template: "{{ switch.turn_on if is_state('trigger.to_state', 'on') else switch.turn_off }}"
    entity_id: switch.relay3

Hi! what’s the mistake?

Try it like this:

service_template: "{{ 'switch.turn_on' if is_state('trigger.to_state', 'on') else 'switch.turn_off' }}"

unsupported action

Post the whole automation config as you have it.