Hi!
I'm new to using ESPHome and HA. I managed to control a modbus RTU board via ESPHome, but as I'm new to HA aswell (was using iobroker before) I realized, that It's better to define my outputs as lights, so they show up in HA as lights, not switches what they are now...
This is my code now (part of):
binary_sensor:
# Read Inputs Board 1 (32 Channels)
- platform: modbus_controller
modbus_controller_id: io_board1
id: in_1_1
name: "${name1_1} Input"
address: 0x00C0
register_type: holding
bitmask: 0x01
internal: true
- platform: modbus_controller
modbus_controller_id: io_board1
id: in_1_2
name: "${name1_2} Input"
address: 0x00C0
register_type: holding
bitmask: 0x02
internal: true
# up to 32 ...
# Control Outputs (Digital Outputs to 25IOB16)
script:
- id: write_output_momentary
parameters:
address: int
controller_id: modbus_controller::ModbusController*
then:
- lambda: |-
auto cmd = modbus_controller::ModbusCommandItem::create_write_single_command(
controller_id, address, 0x0500);
controller_id->queue_command(cmd);
button:
# _________________________ BOARD 1 _________________________
- platform: template
id: outcmd_1_1
name: "${name1_1} Output momentary"
internal: true
on_press:
- script.execute:
id: write_output_momentary
controller_id: io_board1
address: 0x0000
- platform: template
id: outcmd_1_2
name: "${name1_2} Output momentary"
internal: true
on_press:
- script.execute:
id: write_output_momentary
controller_id: io_board1
address: 0x0001
# up to 32 ...
switch:
# _________________________ BOARD 1 _________________________
- platform: template
id: ch_1_1
name: "${name1_1}"
icon: "${icon1_1}"
restore_mode: DiSABLED
lambda: |-
return id(in_1_1).state;
turn_on_action:
- button.press: outcmd_1_1
turn_off_action:
- button.press: outcmd_1_1
- platform: template
id: ch_1_2
name: "${name1_2}"
icon: "${icon1_2}"
restore_mode: DiSABLED
lambda: |-
return id(in_1_2).state;
turn_on_action:
- button.press: outcmd_1_2
turn_off_action:
- button.press: outcmd_1_2
# up to 32 ...
How can I change the switch definition to lights?
It's working right now this way (and should be with switches):
- display a switch witch the current state of the input
- when changing the switch, fire a modbus command (now it switches, but jumps back to off, if the switch did not turn on / the input stays off)
- If the input is set externally (parallel button), the switch should switch to on without firing the modbus command (only publishing)!
I know, I could show/define each entity as light in HA, but' I'd like to avoid defining 80 entites twice, just to list them as lights in HA...
Does someone know a solution?
Is it possible to make a switch. appear as a light. from esphome? - ESPHome - Home Assistant Community
Does not work for me, as I need the light o show the cuurent state based on the modbus input, not the output.
appreciate any hints!