Building Pages in the OH3 UI: documentation draft (2/3)

@RGroll

Thanks for trying to break it down into smaller chunks to understand, however when I try to recreate it, it fails to work. Here is the code after I paste it all back together, done in the widget editor. Any tips why a simple paste together fails to give a working widget?

uid: testWidget
component: f7-card
config:
  title: Chromecast widget example
    - component: f7-block
      config:
        class:
          - padding
      slots:
        default:
          - component: f7-row
            slots:
              default:
                - component: oh-image
                  config:
					# item: =props.prefix+"_Image"
                    url: https://picsum.photos/600/300
                    style:
                      width: 100%
                      height: auto
          - component: f7-row
            config:
              class:
                - padding-top
                - padding-bottom
            slots:
              default:
                - component: f7-col
                  slots:
                    default:
                      - component: oh-player-controls
                        config:
                          item: =props.prefix+"_MediaControl"
						  artistItem: =props.prefix+"_MediaArtist"
						  trackItem: =props.prefix+"_MediaTitle"
                - component: f7-col
                  slots:
                    default:
                      - component: oh-slider
                        config:
                          item: =props.prefix+"_Volume"
                          min: 0
                          max: 100
                          step: 10
                          unit: %
                          label: true
                      - component: oh-button
                        config:
                          text: Stop
                          iconF7: stop
                          fill: true
                          color: red
                          action: command
                          actionCommand: ON
                          actionFeedback: Media Stopped
                          actionItem: =props.prefix+"_Stop"
                          class:
                            - margin-top
          - component: f7-row
            config:
              class:
                - padding-top
                - justify-content-center
              style:
                border-top: 1px solid lightgray
            slots:
              default:
                - component: Label
                  config:
                    text: YouTube Music
					# text: =props.prefix+"_App"
                    style:
                      font-size: 24px

Hi @matt1

I updated the post.

I left out the connecting slots over the different chunks there. For your understanding: Each component has slots (mostly all have a ‘default’ one at least, in which other components sits) which defines if a component sits inside another element.

1 Like

Hi.
There are a couple of formatting errors in your widget. I got it working with the following changes. I’m not the best coder in the world so you might want to double check; and I could not completely test it without waking the house up!
The main ones being ‘title’ needing to be under config (I think) and the unit on the slider needing to be in quotes as you wanted to use the ‘%’ sign.
Hope this helps.

uid: testWidget
props:
  parameters:
    - label: Prefix
      name: prefix
      required: false
      type: TEXT
timestamp: Dec 13, 2020, 3:44:15 AM
component: f7-card
slots:
  default:
    - component: f7-block
      config:
        title: Chromecast widget example
        class:
          - padding
      slots:
        default:
          - component: f7-row
            slots:
              default:
                - component: oh-image
                  config:
                    url: https://picsum.photos/600/300
                    style:
                      width: 100%
                      height: auto
          - component: f7-row
            config:
              class:
                - padding-top
                - padding-bottom
            slots:
              default:
                - component: f7-col
                  slots:
                    default:
                      - component: oh-player-controls
                        config:
                          item: =[props.prefix + '_MediaControl']
                          artistItem: =[props.prefix + '_MediaArtist']
                          trackItem: =[props.prefix + '_MediaTitle']
                - component: f7-col
                  slots:
                    default:
                      - component: oh-slider
                        config:
                          item: =props.prefix +'_Volume'
                          min: 0
                          max: 100
                          step: 10
                          unit: "%"
                          label: true
                      - component: oh-button
                        config:
                          text: Stop
                          iconF7: stop
                          fill: true
                          color: red
                          action: command
                          actionCommand: ON
                          actionFeedback: Media Stopped
                          actionItem: =props.prefix+"_Stop"
                          class:
                            - margin-top
          - component: f7-row
            config:
              class:
                - padding-top
                - justify-content-center
              style:
                border-top: 1px solid lightgray
            slots:
              default:
                - component: Label
                  config:
                    text: YouTube Music
                    style:
                      font-size: 24px
3 Likes

HI Again,

Forgot to say; I think you want “_CurrentTrack” and not “_MediaTitle” for the trackItem parameter on the oh-player-controls. I didn’t correct that in my original reply.

Thank you, it mostly works now. I just wanted it to display all elements, which you have solved that so I can now hopefully learn the secret handshake on how to keep the yaml happy.

@ysc Could you please provide an example how to override a text color for oh-cell?

Is it already possible to set a background image for the automatically created location-cells by ourselves?

I saw it in the youtube-video from the virtual-meetup and it looks awesome.

Yes. Have a look here also
https://community.openhab.org/t/openhab-3-0-milestone-4-discussion/109174/2
Just click on the orange pen on the top and than choose the room and set the background image.
very easy

Thank you very much, I missed that one. Went direct from MR3 to MR5 :stuck_out_tongue_winking_eye:

anyone tried storing a JSON inside a Item? Was able to read and parse it with JSON.parse but can’t figure it out how to write something back. Have an input (time) field and would like t read the time from Json, change it and store it with the sendbutton option

I was able to write json back to string. You need to stringify the JSON object. Otherwise you will paste the whole object to the item but this is not accepted by an string item.

If you use a ECMA script you can use the following:

events.postUpdate(myItemName, JSON.stringify(myJSONObject))

On GUI pages this is not done out of the box. I used find and replace for this but it is ugly. Maybe in the future there will be a better solution available.

Ah thx. Yea already used the JSON stringify but didn’t think about using events.postUpdate ( :sweat_smile:).
Im quite new to JavaScript and run in the problem of using a variable/prop inside the JSON.parse callup like

JSON.parse(items.myitem).wz.mo

is my current syntax which works but i want to use a prop insteadof the “wz” to use the widget dynamically. Any hints? (maybe it’s just to late for me and i dont’see the obvious)

How to do it the easy way? I have to place an URL. I’m missing the upload button.

No upload button - you have to set the path / url to your image.

If you’re on linux, store your images in ‘/etc/openhab/html/’ and link them with ‘/static/yourimage.png’ or use an external URL.

1 Like

Hi @ysc, i have been using the snapshots for past months, and really congrats to all the team to get the final version out
wanted to check if you would have a chance to look at the drop down options for oh-input type widgets, like list items, cards etc. thanks!

Nope probably not until next year - happy holidays!

Thank you. Will use an alternative for now
Happy Holidays!

Hi @hmerk,
I try to color my buttons too.
Your code is working for lights and contacts.

But what is the correct code to change the color with a dimmer light item?

This doesn’t work for me when a dimmer is the item :frowning:
It looks like it only changes the color of the dimmer slider background, but not the button background.

color: ‘=(items.Flur_eingang.state === “0”) ? “” : “blue”’

Thank you!

Lol. What is the status of this ui documentation? Is it ready to be included in the openHAB documentation? Because this thread has completely derailed into a q&a about ui instead of feedback on the documentation.

So either only useful feedback on the documentation page is posted here or this thread should be closed. And if one has a question about the ui open a new topic please.

1 Like

We are rare on documentation contributors as usual. :man_shrugging:
@rlkoshak is working on additional articles for the beginner tutorial.
So far no onw is working on a port to the docs for this yet.

Maybe closing this for now should be the best option.