That didnât work. The switch shows up but returns a command failed error in the logs (I can manually execute the script from the front-end and they work as expected)
but these need to be tied back to HomeKit hence the need to set them as switches.
I would have guessed that having the ability to create a simple switch on a HA platform would be one of the first things - where am I going wrong?
if I read the page correctly, you need to provide an actual shell command for the command_line switch.
You probaly want a âTemplate Switchâ: https://www.home-assistant.io/integrations/switch.template/
You should read this page, however Iâve written your switch as a Template here:
The above returns a config error:
It seems template switches require a value template
â
Invalid config for [switch.template]: required key not provided @ data['switches']['study_aircon']['value_template']. Got None. (See ?, line ?).
YAML configuration reloading
Thanks for pointing me to the right direction though - should be able to figure it out hopefully.
Gotta say one thing though - love the front end of HA + the much better state of integrations.
However I still feel that a simple use case of creating a basic switch should have been a tad more straightforward
It should be pretty easy, is there a reason you need to call a script to turn on your AC? I guess setting a temperature and all that, eh? Mind sharing your two scripts?
Home Assistant needs to know what the current state is - is there a way you can read that data somehow? Does the AC report its status?
If not, you could cheat a little by creating an input boolean (Under Configuration - Helpers) and using that as the value_template. Since that can get out of sync itâs a little wonky.
Probably better to use some sort of button - press button 1 to turn on, and button 2 to turn off, seems to fit your use-case a little better
Actually there are a couple of very specific use cases and all are due to logitech harmony
In 2 of my rooms (that use a Tasmota IR ), I was able to use a pretty nice component from github that allows the HVACs to be setup as climate devices letting me use a nice control wheel to set temps/ modes etc
However 2 other rooms use a logitech harmony that require a specific device command to be issued - e.g.
Yeah, thatâs what I thoughtâŚ
Iâd really suggest using buttons for that since HA canât get the state of the device.
If you still want to use a switch, I can guide you through it, however it may get out of sync with the actual device if something goes wrong.
I will try going the button route - although I am not sure if homekit will interpret it correctly.
Would be incredibly helpful if you could tell me a little more about the input_boolean method so that I can at the very least use it as a workaround for now while I work on porting the remaining devices
The button is just a frontend thing.
If there are no delays in your scripts, you can add âentitiesâ in Lovelace and add the scripts as entities.
There should be an âEXECUTEâ at the right hand side.
Alternatively you can use a (picture) glance and have the buttons map to call your scripts.
Or you could make bigger buttons by adding a âButtonâ in Lovelace. Then edit the on-tap action to call your script.
So the input boolean (as the name suggests) is basically just an internal, virtual switch.
You can create one by going to Configuration - Helpers (e.g. call it âacâ), you now have a input_boolean.ac entity.
Add a homeassistant.turn_off action that turns off input_boolean.ac to your script that turns your AC off (and a âturn_onâ vice-verca)
Thanks - Your solution worked perfectly.
Whatâs even better is that other than creating the input_boolean through code, I could do the rest from the UI directly.
What I did was
a) Create an input_boolean say input_boolean.ht_ac
b) Used lovelace UI to create two automations that link the state of the above boolean to a service call- which triggers the necessary scripts
ok, so the final way with the input boelean created in the helper, then two automations that call service if the created input boolean changes, worked immediately.
However, anybody willing to help with me with my first template?
Shell commands work, tested elsewhere.
Then I have the input boolean but I do not understand how do I change the state by button. In the solution, fedot says:
Add a homeassistant.turn_off action that turns off input_boolean.ac to your script that turns your AC off (and a âturn_onâ vice-verca)
I did this by the common button in lovelace linked to the input boelean entity. Nothing runs, button state changes.
Looking back at my original suggestion I donât even know what I was writing
You wonât need an input_boolean for that, just use the template switch.
So remove the value_template and delete the projector_helper.
As for your switch, take a look at the documentation. Remove the action: call-service from your switch.
For future reference: based on the suggestions fedot provided and samples Vahaldor wrote, here is the final working solution for my similar case using Scripts, this will show up as a separate on and off button next to each other with a bolt icon on the dashboard and works with the main/top card toggle switch aswell.