Unique automation based on calendar event

Hello,
I have a house with 4 rooms, each one having 2 electrical wall sockets.
I created in local calendar an event named lets say “room1”:

calendar_event
start_time: 2023-09-25 21:30:00
end_time: 2023-09-25 22:00:00
message: room1
all_day: false
friendly_name: wall_sockets_calendar

I’ve created these arrays:

{% set rooms = [‘room1’, ‘room2’, ‘room3’,‘room4’] %}
{% set switches1= [‘switch.sonoff_1_relay1’, ‘switch.sonoff_2_relay1’, ‘switch.sonoff_3_relay1’,‘switch.sonoff_4_relay1’] %}
{% set switches2= [‘switch.sonoff_1_relay2’, ‘switch.sonoff_2_relay2’, ‘switch.sonoff_3_relay2’,‘switch.sonoff_4_relay2’] %}

Basically what i want is to create an unique automation that will power on the corresponding room switches during an event calendar.

Multiple events can coexist or could overlap on the same period of time.
Is this possible using HA automation?
Thanks in advance.

When a Calendar Trigger is triggered, the automation’s condition and action have access to these properties.

In other words, the word “room1” must be in the Calendar event’s title or description property. In the following example, I assumed it will be in the Calendar event’s description.

alias: example
variables:
  rooms:
    room1:
      - switch.sonoff_1_relay1
      - switch.sonoff_1_relay2
    room2:
      - switch.sonoff_2_relay1
      - switch.sonoff_2_relay2
    room3:
      - switch.sonoff_3_relay1
      - switch.sonoff_3_relay2
    room4:
      - switch.sonoff_4_relay1
      - switch.sonoff_4_relay2
trigger:
  - id: 'on'
    platform: calendar
    event: start
    entity_id: calendar.your_calendar
  - id: 'off'
    platform: calendar
    event: end
    entity_id: calendar.your_calendar
condition:
  - condition: template
    value_template: "{{ trigger.calendar_event.description in rooms.keys() }}"
action:
  - service: switch.turn_{{ trigger.id }}"
    target:
      entity_id: >
        {{ rooms.get(trigger.calendar_event.description) }}

Seems is not turning on/off the corresponding switches
I get this Error: Template rendered invalid service: switch.turn_on"

Get rid of the trailing ".