{"id":13319,"date":"2021-04-30T16:52:42","date_gmt":"2021-04-30T16:52:42","guid":{"rendered":"https:\/\/www.rjt.org.uk\/home\/?post_type=home_assistant_tip&#038;p=13319"},"modified":"2021-04-30T17:00:40","modified_gmt":"2021-04-30T17:00:40","slug":"lovelace-custom-button","status":"publish","type":"home_assistant_tip","link":"https:\/\/www.rjt.org.uk\/home\/archives\/home-assistant-tip\/lovelace-custom-button\/","title":{"rendered":"Lovelace &#8211; Custom Button"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Prompt user to confirm toggle of Entity<\/h2>\n\n\n\n<p>When switching items like PC&#8217;s make sure they meant it and include what is going to happen.  So you need to prompt based on the sale of the entity.<\/p>\n\n\n\n<p>You need to use a <a rel=\"noreferrer noopener\" href=\"button-card\" target=\"_blank\">custom:button-card<\/a> as the standard card confirmation does not include templating.<\/p>\n\n\n\n<p>The formatting for this is in javascript\/jquery an example is shown below note the odd back tick quotes for the strings.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">  - type: 'custom:button-card'\n    tap_action:\n      action: toggle\n      confirmation:\n        text: |-\n          [[[ \n            if (`${entity.state}` == \"off\")\n            return `Turn ${entity.attributes.friendly_name} On?`;\n            else\n            return `Turn ${entity.attributes.friendly_name} Off?`;\n           ]]]\n    entity: switch.ebony_viii<\/pre>\n","protected":false},"template":"","class_list":["post-13319","home_assistant_tip","type-home_assistant_tip","status-publish","hentry","comments-off"],"_links":{"self":[{"href":"https:\/\/www.rjt.org.uk\/home\/wp-json\/wp\/v2\/home_assistant_tip\/13319","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rjt.org.uk\/home\/wp-json\/wp\/v2\/home_assistant_tip"}],"about":[{"href":"https:\/\/www.rjt.org.uk\/home\/wp-json\/wp\/v2\/types\/home_assistant_tip"}],"wp:attachment":[{"href":"https:\/\/www.rjt.org.uk\/home\/wp-json\/wp\/v2\/media?parent=13319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}