How can I switch 8 binary switches based on the value of a byte variable

Hello all,
I am relatively new to homeassistant, coming from FHEM. So far I am very enthusiastic about the functionality and the huge amount of integrations and adons.
I am running HAOS on a RPI5 with 512GB SSD.
I would need some help with a very special topic:
I have the 1-wire integration running with a DS2408 8-bit IO port whom I am interfacing with an Arduino Nano.
I want to be able to send a byte-value from homeassistant via 1-wire to the DS2408 and do something with this value inside the Nano.
I need the 1-wire connection since WLAN is no choice in this case.
The issue is, that the 1-wire-integration in homeassistant has not implemented the command “PIO(BYTE)” which the DS2408 originally supports.
I have only 8 entities for each port bit with a value of on or off.
I have already read a lot and I think I have to define a template where the calculations from a byte value to the 8 port bits could be done.

Could anyone with more knowledge about the Jinja language give me some hints how I could solve my problem?

If I am on the wrong track with my template approach, I would be happy to get some different advice.

Thanks in advance for support

Are you looking to take 8 entities and make it into 1 or vice versa? I’m not following your explanation. Please post an example of your source entity and it’s state.

the source entity is a byte value which I intend to decrease from 255 to 0 based on time of day (sunrise => 0, sunrise+1 minute => 1, … sunrise+255 minutes => 255)
The destination are 8 binary switches which represent the byte value:

The overall purpose is, to dimup a grow light in a greenhouse in the morning and dimdown in the evening. This is done by the Arduino Nano, connected to the DS2408 with 8 port bits.
I have only the 1-wire connection available, therefore this “not straight forward” approach.
Hope this clarifies my intention.

What are the entity_id’s for the bytes?

switch.29_045717000000_programmierter_ein_ausgang_0
switch.29_045717000000_programmierter_ein_ausgang_1
.
.
.
.
.
switch.29_045717000000_programmierter_ein_ausgang_7

use this in a template sensor

{% set entities = [
'switch.29_045717000000_programmierter_ein_ausgang_0',
'switch.29_045717000000_programmierter_ein_ausgang_1',
'switch.29_045717000000_programmierter_ein_ausgang_2',
'switch.29_045717000000_programmierter_ein_ausgang_3',
'switch.29_045717000000_programmierter_ein_ausgang_4',
'switch.29_045717000000_programmierter_ein_ausgang_5',
'switch.29_045717000000_programmierter_ein_ausgang_6',
'switch.29_045717000000_programmierter_ein_ausgang_7',
] %}
{% set bin = entities | map('states') | map('replace', 'on', '1') | map('regex_replace', 'off|unknown|unavailable', '0') | join('') %}
{{ int(bin, 2) }}

It will output an integer between 0 and 255

if you want to get spicy, we can turn this into a template number so that you have a slider that can adjust the state.

EDIT:
If you want to use an template number, use this as the action for set_value:

- variables:
    entities:
      - switch.29_045717000000_programmierter_ein_ausgang_0
      - switch.29_045717000000_programmierter_ein_ausgang_1
      - switch.29_045717000000_programmierter_ein_ausgang_2
      - switch.29_045717000000_programmierter_ein_ausgang_3
      - switch.29_045717000000_programmierter_ein_ausgang_4
      - switch.29_045717000000_programmierter_ein_ausgang_5
      - switch.29_045717000000_programmierter_ein_ausgang_6
      - switch.29_045717000000_programmierter_ein_ausgang_7
    filtered_entities: >
      {% set bin =  '{:08b}'.format(value) %}
      {% set ns = namespace(ret=[]) %}
      {% for bit in bin %}
        {% if bit == '1' %}
          {% set ns.ret = ns.ret + [entities[loop.index-1]] %}
        {% endif %}
      {% endfor %}
      [{{ ns.ret }}, {{ entities | reject('in', ns.ret) | list }}]
- parallel:
  - action: switch.turn_on
    target:
      entity_id: "{{ filtered_entities[0] }}"
  - action: switch.turn_off
    target:
      entity_id: "{{ filtered_entities[1] }}"

I’m sure it can be optimized

I2C, SPI, or actually 1-wire? Can’t you use serial, something common across pretty much everything? Is the DS2408 necessary? Can’t you just use 8 GPIOs on the remote end on your Nano?

Make and model please, so I can understand your challenge better.

Can’t the Arduino be replaced with an ESP fairly easily?

Nevermind just noticed the WLAN is not an option part of the post

@petro: thank you very much for your help; I have to dig into this to understand since as I said I am not a Jinja-Specialist; most probalby I willl come back with some questions

@IOT7712:
I tried to draw a diagram how my setup is; hope that helps to clarify.
The 1-wire line is buried in my garden and the DS2408 and the Arduino is in a waterproofed case in my greenhouse and I do not want to touch this setup