{"id":5041,"date":"2023-09-23T10:16:09","date_gmt":"2023-09-23T08:16:09","guid":{"rendered":"https:\/\/www.sigalou-domotique.fr\/?p=5041"},"modified":"2026-01-02T17:00:50","modified_gmt":"2026-01-02T15:00:50","slug":"je-cree-un-switch-on-off-virtuel-persistant-home-assistant","status":"publish","type":"post","link":"https:\/\/www.sigalou-domotique.fr\/en\/je-cree-un-switch-on-off-virtuel-persistant-home-assistant","title":{"rendered":"I create a virtual switch on\/off (persistent)"},"content":{"rendered":"<p>In order to be able to tell my automations or scripts whether or not I allowed automatic watering, I wanted to create a \u2018virtual\u2019 switch, which has no link with any entity (i.e. not a template) and which keeps its state when the (persistent) Home Assistant is relaunched.<\/p>\r\n<p><a href=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/09\/switchvirtuel.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5042\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/09\/switchvirtuel.gif\" alt=\"\" width=\"376\" height=\"34\" \/><\/a><!--more--><\/p>\r\n<h3>I create an input _boolean<\/h3>\r\n<h4>Option 1: By configuration.yaml<\/h4>\r\n<p>In my _yaml configuration file, I will add my virtual switch<\/p>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\">input_boolean: _automatic watering: #input_boolean.arrosage_automatic name: Authorized watering icon: mdi:sprinkler-variant<\/pre>\r\n<h4>Option 2: Through the graphical interface<\/h4>\r\n<p>I go to Settings \/ Devices and Services \/ Inputs \/ Create Input \/ Switch\u00a0<\/p>\r\n<p><a href=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/09\/arrosageautorise4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5051\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/09\/arrosageautorise4.png\" alt=\"\" width=\"408\" height=\"255\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/09\/arrosageautorise4.png 408w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/09\/arrosageautorise4-300x188.png 300w\" sizes=\"auto, (max-width: 408px) 100vw, 408px\" \/><\/a><\/p>\r\n<h3>I'll customize his icon<\/h3>\r\n<p>This is done in the customized.yaml file to be declared in the configuration.yaml file<\/p>\r\n<p><a href=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/09\/customize.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5129\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/09\/customize.png\" alt=\"\" width=\"245\" height=\"123\" \/><\/a><\/p>\r\n<p><a href=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/09\/customize2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5130\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/09\/customize2.png\" alt=\"\" width=\"465\" height=\"208\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/09\/customize2.png 465w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/09\/customize2-300x134.png 300w\" sizes=\"auto, (max-width: 465px) 100vw, 465px\" \/><\/a><\/p>\r\n<p>In this customized.yaml file I add these lines<\/p>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\">input_boolean.watering_automatic: templates: icon: &gt; return (state === 'on')? 'mdi:sprinkler-variant' : 'mdi:water-off'; icon_color: &gt; return (state === 'on')? 'green': 'rgb(54, 95, 140)';<\/pre>\r\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>In order to be able to tell my automations or scripts whether or not I allowed automatic watering, I wanted to create a \u2018virtual\u2019 switch, which has no link with any entity (i.e. not a template) and which keeps its state when the (persistent) Home Assistant is relaunched.<\/p>","protected":false},"author":1,"featured_media":5047,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[14,53,166],"tags":[81,62],"class_list":["post-5041","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-domotique","category-home-assistant","category-retex","tag-developpement","tag-switch"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/posts\/5041","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/comments?post=5041"}],"version-history":[{"count":0,"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/posts\/5041\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/media\/5047"}],"wp:attachment":[{"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/media?parent=5041"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/categories?post=5041"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/tags?post=5041"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}