I’d like to set the initial states of several input controls with values from a workflow rather than a specific logged attribute from a device.
The reasoning is our device implements the possibility of setting a 10 different profiles with 46 different values, mostly booleans and time fields.
I would like to save each of these profiles as attributes in Losant as condensed strings, only parsing them on demand as otherwise my Losant devices will have hundreds of values which would become fairly cumbersome.
I should be able to get around it by building an experience view, but the dashboard look and interaction is really nice, so I’d prefer to go that route.
Is this possible at the moment, or is it something you have been looking to implement?
That’s not something that’s currently possible using our built-in Input Controls. We’ll have to brainstorm additional ways to set input values beyond device state.
An interesting workaround could be to embed an Experience View in a dashboard using the External Website Block. You can use Experience Views to build just the input controls you’d like, and then embed those in an existing dashboard. Gives you kind of the best of both worlds.
Check if the profile_select url parameter is not null. (If it is, it means I’m rendering a list of all the profiles, so there’s a different function that gets all the profile strings, then loops through them and parses out the name and enabled bit to use for a list presentation.)
If so, go to the switch. (I didn’t find a streamlined way to automate this, so I ended up with the switch solution, it gives me what I need to make it work well although it took a little while to draw everything up).
Get the value that contains the corresponding profile string from the device and dump it into a reasonable spot in the payload. (data.profile in my case)
Split the value (I’m using : as a seperator, and just storing it back to the JSON in the same subkey it came from).
A parser for my time values to make them fit nicely into HTML time fields. (I’m sending them as hex coded numbers that correspond to minute of the day, i.e. 4b0 (1200) for 20:00, I’ve just done the parsing in JS, I’ll pop my code for that in the bottom in case it is of interest).
Render the page using data.profile as the custom page data payload path.
This gives the page access to all the subvalues of the string like so for example: {{pageData.values.[21]}}
At the moment I’ve not built it into a dashboard, it’s just a standalone page on my Experience page, and currently looks something like this:
Next step is to do the form submit, I’m not quite finished with that at the moment.
Time parsing code:
Define two variables to hold hours and minutes (I reuse these for all the values)
var hour, minute; Convert the value to a base 10 int from hex
payload.data.profile.values[15] = parseInt(payload.data.profile.values[15], 16); Add a zero in front, calculate the hours (value - partial hours / 60) and cut the last two digits
hour = (“0” + (payload.data.profile.values[15] - (payload.data.profile.values[15] % 60)) / 60).slice(-2); Add a zero in front, calculate the minutes (remainder of value / 60) and cut the last two digits
minute = (“0” + (payload.data.profile.values[15] % 60)).slice(-2); Put the two variables together in a nicely formatted time string
payload.data.profile.values[15] = hour + “:” + minute; ‘’