Sonofflan - toggle as a template?

Hi all,

I have managed to connect my sonoff wall switch using sonofflan from hacs.

everything works well in lovelace. I am trying to create an automation that would '‘çopy’ the ‘‘toggle’’ function of a switch device.

At the moment i have 2 separate automation one to turn on if lights are off and another to turn off if the lights are on. The reason is that the sonoff device/integration does not support TOGGLE.

is there a way to add it to one?

alias: Laura_button_bathroom (Duplicate)
description: ''
trigger:
  - device_id: button
    domain: zha
    platform: device
    type: remote_button_short_press
    subtype: remote_button_short_press
condition:
  - condition: state
    entity_id: light.wallswitch_channel1
    state: 'off'
action:
  - service: sonoff.send_command
    data:
      device: wallswitch
      switches:
        - outlet: 0
          switch: 'on'
  - service: sonoff.send_command
    data:
      device: wallswitch
      switches:
        - outlet: 1
          switch: 'on'
mode: single


tried a template but getting nowhere

service: >
  {% if is_state('light.sonoff_100095c8f1_1','off') %}
    light.turn_on
  {% else %}
    light.turn_off
  {% endif %}
entity_id: light.sonoff_wallswitch_1

Your template seems like it should work. Is it referencing the correct entities? Verify in Developer tools that the entity names are correct.
Also check your logs and see if there are related errors.
Post the whole automation you are testing.

This is the last one i have - i am not actually using light.wallswitch in the automation (should have probably posted it in OP, i cant cant seem to adjust to fit the -call service

alias: Laura_button_bathroom
description: ''
trigger:
  - device_id: button
    domain: zha
    platform: device
    type: remote_button_short_press
    subtype: remote_button_short_press
condition: []
action:
  - service: sonoff.send_command
    data:
      device: wallswitch
      switches:
        - outlet: 0
          switch: 'on'
  - service: sonoff.send_command
    data:
      device: wallswitch
      switches:
        - outlet: 1
          switch: 'on'
mode: single

edit: Note that these show up as entities not devices

You could try something like this:

alias: Laura_button_bathroom
description: ''
trigger:
  - device_id: button
    domain: zha
    platform: device
    type: remote_button_short_press
    subtype: remote_button_short_press
condition: []
action:
  - service: sonoff.send_command
    data:
      device: wallswitch
      switches:
        - outlet: 0
          switch: "{{ 'on' if is_state('light.wallswitch_channel0', 'off') else 'off' }}"
  - service: sonoff.send_command
    data:
      device: wallswitch
      switches:
        - outlet: 1
          switch: "{{ 'on' if is_state('light.wallswitch_channel1', 'off') else 'off' }}"
mode: single

You still need light.wallswitch_channel1 for the condition, so I’m not sure why you don’t want to just use the light.turn_on and light.turn_off services.

Thank you I didn’t know i could actually uses call services on entities!!! just used lights.toggle and works well. Will still experiment with using templates in config yaml to check how they work…

cheers