Hello,
I have recently started with HA and I am configuring a telegram bot, to facilitate the management of the system from outside the home.
The first thing I did was to set up some sonoffs for the lights that already work for me, but when I try to integrate them with the bot they do not work for me.
I’m trying to make the command by step parameters allow me to turn the lights on or off independently.
This is the code that I created, when I check it from HA it tells me that it is correct in structure, but I can not get it to work.
He sends me the light message on but does not turn on the corresponding light.
Everything after the condition will not execute if the value template is not met. That way you wont run into unforeseen issues when you don’t provide an entity_id.
As you say you had the following error in the log:
Log Details (ERROR)
Mon Sep 18 2017 12:14:54 GMT + 0200 (CEST)
Invalid service data for switch.turn_on: Entity ID is an invalid entity id for dictionary value @ data ['entity_id']. Got ''
I have tried the code that you have modified me and the condition never enters.
If I remove the condition and the rest works correctly and I see that the testo that gives me the telegram bot is the following
You need to find out what you get when you call args. In the python world, that will return a list of values without keywords. So if the data passed back inside trigger.event.data is {“x”:“a”, “y”,“b”}, then when you request args you should get [“a”,“b”]. You’ll never get 1. The condition you have is saying trigger.event.data[“args”] == 1, based on that information the condition will never be true.
So your first order of business is to find out what you actually get from ‘args’. Once you figure that out, you need to figure out what attribute you want to write your condition based off of.
In almost all cases, I could see you avoiding ‘args’ all together. Instead your condition will be based on a keyword inside your data dictionary. Using the example I listed above, the condition would look like:
if trigger.event.data[‘x’] == ‘a’.
So ask yourself, what am I trying to achieve? What data do I want to use to conditionally message myself?
I can’t follow what you are trying to do. All the code you are posting shows me that you are over complicating this. To me based on your if statements, you don’t need a condition at all because nothing is changing between each condition. If that truly is the case, this should work:
In regards to using [0], that shouldn’t make a difference because both return the same value.
Calling a postion a larger string makes sense, but in your case it doesn’t. Example my string is “MYSTRING”. I want the first postion, “MYSTRING”[0] would return “M”. You are calling trigger.event.data[‘args’], which will return a string according to you:
meaning that the respose for calling [‘args’] would be ‘1’. and ‘1’[0] will return the first position in the string ‘1’, which is ‘1’.
So My question is, Are you just trying to change the message based on the event data?