Hi,
I’m trying to get my dashboard to switch between my different floors, based on a helper (input_text.floorplan_selection_by_browser) that contains a json file in wich I keep the device from wich I’m browsing, and the floor that needs to be shown in the dashboard.
Example of the helper’s content:
{"browser_mod_<phone>":"Ground Floor","browser_mod_<pc>":"First Floor"}
After some AI assistance I got to something that resembles (trimmed it down, to the bare essentials for this problem) the following for my dashboard. (which is a picture elements card)
type: picture-elements
image: /local/floorplan/floorplan background.png
elements:
- type: custom:state-switch
entity: template
template: |
[[[
const raw = entity?.state || '{}';
let obj = {};
try { obj = JSON.parse(raw); } catch (e) { obj = {}; }
const bid = window.browser_mod?.browserID;
const floor = (bid && obj[bid]) ? obj[bid] : 'Ground Floor';
return floor;
]]]
states:
Ground Floor:
- image: /local/floorplan/groundfloor.png
style:
left: 50%
pointer-events: none
top: 50%
width: 100%
type: image
First Floor:
- image: /local/floorplan/firstfloor.png
style:
left: 50%
pointer-events: none
top: 50%
width: 100%
type: image
Second Floor:
- image: /local/floorplan/secondfloor.png
style:
left: 50%
pointer-events: none
top: 50%
width: 100%
type: image
- type: custom:button-card
entity: input_text.floorplan_selection_by_browser
show_name: false
show_state: false
show_icon: false
show_entity_picture: true
entity_picture: |
[[[
const raw = entity?.state || '{}';
let obj = {};
try { obj = JSON.parse(raw); } catch (e) { obj = {}; }
const bid = window.browser_mod?.browserID;
const floor = (bid && obj[bid]) ? obj[bid] : 'Ground Floor';
if (floor === 'First Floor') return '/local/floorplan/floor_icons/FirstFloor.png';
if (floor === 'Second Floor') return '/local/floorplan/floor_icons/SecondFloor.png';
return '/local/floorplan/floor_icons/GroundFloor.png';
]]]
styles:
card:
- background: none
- box-shadow: none
- padding: 0px
style:
left: 5%
top: 20%
width: 5%
tap_action:
action: call-service
service: script.floorplan_cycle_for_browser
service_data:
browser_id: "[[[ return window.browser_mod?.browserID; ]]]"
hold_action:
action: more-info
I’m guessing the problem has to do with the template being set with jinja and set to the entity of the state-switch. (downloaded via hacs, as wel as browser_mod) But can’t figure out what goes wrong.
Can anny of you help me?
Thx!