Yes, add it to configuration.yaml, one entry per switch. Make sure you copy the right tasmota topics for each switch
@mcblok - what does your template switch look like? I created one but still have the issue of Google Assistant toggling the light when using a “turn off all the lights” command. Here’s my setup…
switch:
- platform: template
switches:
entryway_lights_switch:
friendly_name: "Entryway Lights Switch"
value_template: "{{ is_state('switch.LOLTEST', 'on') }}"
turn_on:
service: switch.turn_on
data:
entity_id: switch.LOLTEST
turn_off:
service: switch.turn_off
data:
entity_id: switch.LOLTEST
- platform: mqtt
name: "LOLTEST"
icon: "mdi:lightbulb"
state_topic: "stat/tasmota-sw-entrance/POWER1"
state_off: "OFF"
state_on: "ON"
command_topic: "cmnd/tasmota-sw-entrance/POWER2"
payload_on: "2"
payload_off: "2"
availability_topic: "tele/tasmota-sw-entrance/LWT"
payload_available: "Online"
payload_not_available: "Offline"
This is the template switch:
basement_stairs_google:
friendly_name: Basement Stairs Light
value_template: "{{ is_state('switch.basement_stairs', 'on') }}"
turn_off:
service: script.turn_entity_on_off_if_not_already
data:
entity_id: 'switch.basement_stairs'
on_off: 'off'
turn_on:
service: script.turn_entity_on_off_if_not_already
data:
entity_id: 'switch.basement_stairs'
on_off: 'on'
Add this to script.yaml:
turn_entity_on_off_if_not_already:
sequence:
- condition: template
value_template: '{{ not is_state(entity_id, on_off) }}'
- service_template: homeassistant.turn_{{ on_off }}
data_template:
entity_id: '{{ entity_id }}'
mode: parallel
max: 10
Awesome that worked!!! Thank you for sharing…this has been driving me nuts
Your original template worked for me as a switch
for my Treatlife 3 Way without any rules.
Now I am in the process of adding the template switch basement_stairs_google:
and scripts.yaml
, but I am running into some issues.
configuration.yaml
switch:
- platform: mqtt
name: "mcblok 3 way"
icon: "mdi:lightbulb"
state_topic: "stat/mcblok/POWER1"
state_off: "OFF"
state_on: "ON"
command_topic: "cmnd/mcblok/POWER2"
payload_on: "2"
payload_off: "2"
availability_topic: "tele/mcblok/LWT"
payload_available: "Online"
payload_not_available: "Offline"
- platform: template
switches:
mcblok_google:
friendly_name: Test Light
value_template: "{{ is_state('switch.mcblok', 'on') }}"
turn_off:
service: script.turn_entity_on_off_if_not_already
data:
entity_id: 'switch.mcblok'
on_off: 'off'
turn_on:
service: script.turn_entity_on_off_if_not_already
data:
entity_id: 'switch.mcblok'
on_off: 'on'
scripts
script:
turn_entity_on_off_if_not_already:
sequence:
- condition: template
value_template: '{{ not is_state(entity_id, on_off) }}'
- service_template: homeassistant.turn_{{ on_off }}
data_template:
entity_id: '{{ entity_id }}'
mode: parallel
max: 10
But I am getting the following error when trying to check the configuration.
Error loading /config/configuration.yaml: while parsing a block collection
in "/config/scripts.yaml", line 4, column 7
expected <block end>, but found '?'
in "/config/scripts.yaml", line 9, column 7
Try to remove script: in scripts.yaml and make sure the indentation is correct
Hi Folks… I know is an old thread but it seemed to closest to solving my issue with my Treatlife 3 way switches. I want to create a template using @mcblok solution. I have two different states on my Treatlife 3 way switch after I flashed with Tasomota… one for the state of load (i.e. light) and one for position of the switch itself. I want to use a variation of your solution to create a template switch that will figure out what position to put the switch in to turn it on or off depending on the current state of the light:
`switch:
- platform: template
switches:
mbedroom_light_tmp:
friendly_name: Master Bedroom Light
unique_id: test123
value_template: “{{ is_state(‘switch.parentsbedroomlight’, ‘on’) }}”
turn_off:
service: script.turn_entity_on_off_if_not_already
data:
entity_id1: ‘switch.parentsbedroomlight’
entity_id2: ‘switch.tasmota2’
on_off: ‘off’
turn_on:
service: script.turn_entity_on_off_if_not_already
data:
entity_id1: ‘switch.parentsbedroomlight’
entity_id2: ‘switch.tasmota2’
on_off: ‘on’`
and the associated script:
`turn_entity_on_off_if_not_already:
sequence:
- condition: template
value_template: ‘{{ not is_state( entity_id1, on_off) }}’ - service_template: homeassistant.turn_{{ on_off }}
data_template:
entity_id: ‘{{ entity_id2 }}’
mode: parallel
max: 10`
bear in mind that entity_id1 is for the state of the load of the Treatlife 3 way switch (i.e. light) whereas entity_id2 is the state/position of the same switch.
No errors in the YAML… and the script will indeed execute but the light doesn’t change… in fact the template switch will turn on… nothing happens (to the ‘real’ 3 way switch), then puts itself back to an off position. Looking at the script detailed info, it appears that the script did indeed execute, seemingly correctly?
`Executed: January 21, 2022, 6:35:57 PM
Result:
params:
domain: homeassistant
service: turn_on
service_data:
entity_id: switch.tasmota2
target: {}
running_script: false
limit: 10`
i’m obviously missing something… and would love to get this working. Thx in advance.