Is there a way to Use a condition with a counter that if it is a the numeric value of 2 for 3 seconds the automation will trigger?
I have a counter based on the number of times a switch has been turned on. So I essentially want if the Counter has been at number 2 for 3 seconds it will reset to 0.
I am essentially trying to create an automation for a Double/Triple tap on a sonoff switch. So the counter increases by 1 each time the switch is tapped but if it has only been on a number of 2 (For Double Tap) for 3 seconds (yes this may not be realistic) It will trigger an automation to turn on a light but also to reset the counter to 0(Zero).
That would toggle light_1 for one press, light_2 for two presses, and light_3 for any other number of presses then reset the counter. The condition just keeps it from triggering again when itâs reset to zero.
Note: Iâm on my phone so the syntax or formatting might need some fixing.
I have tried the below and HA dashboard says there is an invalid configuration along with the configurator checker. I know it has to do with this part of the code since if i comment it out it works fine but I dont know what as neither of them tell me what line is causing the issues. Am i missing something?
Here is what i get now when I do a check config in HASSIO.
Testing configuration at /config
2018-02-25 13:02:32 ERROR (SyncWorker_0) [homeassistant.util.yaml] mapping values are not allowed here
in â/config/automations.yamlâ, line 679, column 19
2018-02-25 13:02:32 ERROR (MainThread) [homeassistant.bootstrap] Error loading /config/configuration.yaml: mapping values are not allowed here
in â/config/automations.yamlâ, line 679, column 19
Here is the config. Line 679 is the data_template line.
I still get a Invalid configuration on the Automation Yaml file but it is not specific to lines now. Is trigger.entity_id correct or should enitity_id be replaced with an actual ID.
Sorry for going back and forth on this I dont understand templates still.
I am stumped. I have tried adding and removing spacing but I still get the message when HA is restarted that Automation is an invalid config along with if i do check config. The frustrating part is it doesnât show any errors in the hassio logs and when the check config fails it doesnât tell me anything.
Any help would be greatly appreciated as I do not understand templates. This one makes sense to me and seems as though it should work but its not. Does entity_id in the trigger.entity_id actually need to be a valid Entity id? Thats the only other thing that I could think of.
2018-02-27 17:09:06 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: dependency violation - key âforâ requires key âtoâ to exist @ data[âtriggerâ][0]. Got None. (See /config/configuration.yaml, line 62). Please check the docs at https://home-assistant.io/components/automation/
Line 62 in my configuration.yaml file is
group: !include groups.yaml
Edited, Researching a little more I was able to get the Tap counter to work along with resetting with the below however the switches do not turn on. any thoughts?
trigger.entity_id shouldnât be in quotes. trigger is a variable that gets passed to your templates containing useful information about the event that triggered the automation:
The error youâre seeing is because itâs always hitting the else case. In that case, thereâs not a valid entity_id since itâs left empty, so the switch.turn_on service is complaining that it didnât get the right data.
An easy workaround would be to just create a dummy template switch just to toggle in the else case or just put switch.philsoffice_switch in the else case so that it gets used for any count > 1.
A cleaner solution if you want to limit it to only acting for 1 or 2 taps might be to try changing the order of the services and using a condition to keep it from calling switch.turn_on for count > 2:
Note that I had to use trigger.to_state.state to get the state of the counter when the automation was triggered instead of getting the current state for trigger.entity_id since with this approach the counter has already been reset before we check the state.
I was able to finally get to try this out and it works. I used the original and I think there were two issues. One was having the trigger.entity_id in quotes and the other was not having above: 0 in the trigger. I added another switch to the else so that would work. The little things in the code can throw everything off.
If i wanted to have more than 3 taps i could just keep adding the elif lines correct?
the next question would be. Would it possible to add a condition in this same automation to turn the lights on if they are currently off and vica versa or would that be easier by a dummy switch to use in this automation and have the dummy switch be the trigger in another automation that would have that condition?
are you able to get all of your automation in the preformated text? The -alias looks like its in it but the rest of it is not.
Instead here is what I have. As a note it has been a long time since I worked on this and have not installed the switch in this manner yet so I do not have the ability to test but it should be the way it was when I said i had it working above. I think you are missing the counter.tap entity.