Consolidate Switches

Hey folks,
I’m trying to create a toggle switch out of two push buttons. Like this:

  1. a_on (need a “on” signal for switching on - simply sending the RF “on” command thru the Sonoff bridge)
  2. a_off (need a “on” signal for switching off - simply sending the RF “off” command thru the Sonoff bridge)

The push buttons work well seperately. Now I started to use the HA template:

The new switch.skylight turns on by toggling. But the toggle switches back automaticallyso I’m not able to switch the light off anymore.

Could you tell my why the toggle is switching back and why am I not able to toggle the switch.a_off “on” command? Where is the mistake in the switch-config?

Here is my YAML-Configuration:

switch:
  - platform: template
    switches:
      skylight:
        value_template: "{{ is_state('sensor.skylight', 'on') }}"
        turn_on:
          service: switch.turn_on
          target:
            entity_id: switch.a_on
        turn_off:
          service: switch.turn_on #turn on because the a_off needs an on signal for sending the RF-Signal
          target:
            entity_id: switch.a_off

Thank you in advance guys.

Is this sensor changing state?

is_state('sensor.skylight', 'on')

honestly I’ve no idea. I just took it over from the template.

By deleting this line I get:
grafik

This works fine but I’d like to have a toggle. If I get your question right, on a_on and a_off sending states: yes they do have states but just a short signal when sending the RF-Signal (the toggles finally switches also back fast). So do I need a line to hold the state?

You have no idea if your sensor is changing state?

Is this a contact sensor on the skylight?

This sensor state is the only thing that determines the switch “toggle” state. It is the feedback to home assistant that tells it the state of the skylight switch .

Yes, there is a short status message “ON” for both switches but there are no special programmed sensors for “holding” states like:

If toggling a_on or a_off

  1. value: “on” for a part of a second (sending RF-command)
  2. value: “” after toggling
    .

I just wanted to let you know that I do not know what this line means

I did not ask you about your a_on and a_off switches. They are no use for feedback as they do not have permanent states.

This line:

value_template: "{{ is_state('sensor.skylight', 'on') }}"

Determines the state of your skylight switch. If the template resolves to true then your skylight switch will appear on.

Do you have a sensor on the skylight?

If you don’t then Home Assistant has no way of knowing what state the switch is in. So it uses this type of switch:

6ca380e8bccad056c5300f623e84676cae310c3d

So that you can always turn it on or off.

now I got you. There is no sensor.skylight with status “on/off” at the moment. Finally I need to create one based on trigger event
a_on → sensor.skylight (Status: on)
a_off → sensor.skylight (Status: off)

I’m a newbee in creating my own sensors. I found this:

I tried tried to modify but its not working.

template:
  - trigger:
      - platform: state
        entity_id: binary_sensor.skylight
  - sensor:
      - name: "skylight"
        state: >
          {%- if states('switch.a_on') -%}
            {{ states('sensor.skylight'), 'on' }}
          {%- endif -%}
          {%- if states('switch.a_off') -%}
            {{ states('sensor.skylight'), 'off' }}
          {%- endif -%}

Do you have an approach for this?

Stop trying to use entities that you don’t have. You have no binary_sensor.skylight

They won’t just magically appear because you make them up. You have to define them.

This might work:

template binary sensor

template:
  - trigger:
      - platform: state
        entity_id: switch.a_on
        to: 'on'
        id: 'true'
      - platform: state
        entity_id: switch.a_off
        to: 'on'
        id: 'false'
    binary_sensor:
      - name: "skylight"
        state: "{{ trigger.id }}"

template switch

switch:
  - platform: template
    switches:
      skylight:
        value_template: "{{ is_state('binary_sensor.skylight', 'on') }}"
        turn_on:
          service: switch.turn_on
          target:
            entity_id: switch.a_on
        turn_off:
          service: switch.turn_on #turn on because the a_off needs an on signal for sending the RF-Signal
          target:
            entity_id: switch.a_off

Thank you for your reply and your approach @tom_l. The switch works but the switch still jump back instantly. I’ll take my time for it tomorrow whats going on there and need to be changed.