That worked to make the template for the main value of the sensor work (which in and of itself is a big help) when I take out the attributes like this:
2019-05-15 23:47:16 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/config/custom_components/variable/__init__.py", line 179, in async_set_variable
attributes = json.loads(attributes_template.async_render({ 'variable': current_state }))
File "/usr/local/lib/python3.7/json/__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python3.7/json/decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Invalid control character at: line 5 column 50 (char 188)
I’m guessing it’s choking on some characters in the attributes and crashing?
one could of course try that, but this is the format that been working for me ever since I started using CC variable, posted above at:
yes, and its doing so in variable while getting the ‘current state’ of the entity_id.
must confess the templates renders fine in my dev-template.
You do have quotes around the entity_id in the condition though, which shouldn’t be there… seems a long shot, but please take these out and see what gives.
So, I’ve got some of the attributes working. In the case of all 4 variables I was using, it was the body of the email that was causing the problem (in addition to the wrong syntax I had before). It’s quite obvious to me now that the body of the email is just too big for the string that the variable uses to hold it’s data. So, for now I will use it without the body of the email. The below syntax works:
There’s something special about the bodies of each of those 4 different emails sent to 4 different variable’s attributes that’s making it blow up whereas the subject, from and to do not… Either length or some characters in them… Either way, I can’t use it for email bodies the way it is now…
I’ve been trying to get this working, with no luck. Most all of the instructions and posts I’ve read, say to copy the “variable.py” to “custom_components”. So I did. But that file is not on github, I just happened to find it posted here, and a also or more recent version. Which is odd, since the readme on github specifically states to use “variable.py”. Where is it??
I then read on another thread to copy the three files in the “variable” folder on github into “custom_components/variable/”, so I did that. It still does not work. I am getting an error:
Setup failed for variable: No setup function defined.
I show no “variable” service.
I have a very simple variable set up in my configuration, nothing complicated.
I have custom updater running in that folder, so I know that much isn’t the problem. Reading through the posts here, it seems so simple, but after looking at github, and reading other posts, it’s incredibly confusing. I am by no means knowledgeable about home assistant, but I’m learning, and this is the first thing haven’t been able to get working.
Also I found a related SQL error… sensor.dpd_packages_coming_today is the exact same sensor, just with different email content for a different shipping provider. Here’s the error:
Above code works fine, calls another script.google_home_turn_on using the correct passed ‘device’, but if I try to change ‘media_player.craft_room_google’ (like above) to device (shown below) [to make it dynamic], it fails.
2019-08-28 18:02:34 ERROR (MainThread) [custom_components.variable] Could not render value_template variable.last_volume: UndefinedError: ‘device’ is undefined
Assuming it’s something in the custom_component that’s not allowing the ‘passed’ device variable from being used. Trying to just use a single dynamic script if at all possible @rogro82 . Thx!