At home Card

Hi,
With the help of all of you, but mostly from @JustinG (thank you so much!) I have built a card widget to display who is at home:

image

This card widget displays an image in a row for every member of the family in gray if not at home and in color if at home.
It also displays a list of non-family visitors if at home.
All items are linked to their analyzer.

Here is the code:

uid: at_home_card
tags:
  - presence
props:
  parameters:
    - default: At home
      description: "Default: 'At home'"
      label: Title
      name: title
      required: false
      type: TEXT
    - context: item
      default: Family
      description: Items group of people who are family members. Items must be switch and indicate presence.
      label: Family group
      name: family
      required: true
      type: TEXT
    - default: "Visitors:"
      description: "Default: 'Visitors:'"
      label: Visitors title
      name: visitorsTitle
      required: false
      type: TEXT
    - context: item
      default: NotFamily
      description: Items group of people who are not family members. Items must be switch and indicate presence.
      label: Not family group
      name: notFamily
      required: true
      type: TEXT
    - default: presence
      description: Folder containing images ($OPENHAB_CONF/html/name-of-the-folder). One white space for no folder.
      label: Image folder
      name: imageFolder
      required: true
      type: TEXT
    - default: png
      description: Extension of files.
      label: Extension
      name: extension
      required: true
      type: TEXT
    - default: rgba(245,210,210,1)
      description: Card background gradient top color. Hex or RGBA.
      label: Background gradient top color
      name: bggradienttopcolor
      required: false
      type: TEXT
    - default: rgba(255,245,245,1)
      description: Card background gradient bottom color. Hex or RGBA.
      label: Background gradient bottom color
      name: bggradientbottomcolor
      required: false
      type: TEXT
  parameterGroups: []
timestamp: Mar 23, 2023, 11:33:14 AM
component: f7-card
config:
  class:
    - padding
  style:
    --f7-card-header-border-color: transparent
    --f7-card-header-font-weight: 700
    background: ='linear-gradient(to bottom, '+props.bggradienttopcolor+', '+props.bggradientbottomcolor+')'
    border-radius: var(--f7-card-expandable-border-radius)
    box-shadow: 5px 5px 10px 1px rgba(0,0,0,0.1)
    noShadow: false
slots:
  default:
    - component: f7-row
      slots:
        default:
          - component: f7-col
            slots:
              default:
                - component: Label
                  config:
                    style:
                      color: rgba(50,50,50,1)
                      font-size: 26px
                      font-weight: 600
                      letter-spacing: .75px
                      overflow: hidden
                      padding-bottom: 10px
                      text-overflow: ellipsis
                      text-shadow: 2px 2px rgba(80,80,80,.25)
                      white-space: nowrap
                    text: =props.title
    - component: f7-row
      slots:
        default:
          - component: oh-repeater
            config:
              filter: true
              for: familyMember
              fragment: true
              groupItem: =props.family
              sourceType: itemsInGroup
            slots:
              default:
                - component: f7-col
                  slots:
                    default:
                      - component: f7-col
                        slots:
                          default:
                            - component: oh-image
                              config:
                                action: analyzer
                                actionAnalyzerItems:
                                  - =loop.familyMember.name
                                style:
                                  filter: =items[loop.familyMember.name].state=="ON"?"":"grayscale(100%) opacity(50%)"
                                  object-fit: cover
                                  width: 100%
                                url: ="/static/"+(props.imageFolder!=" "?props.imageFolder+"/":"")+loop.familyMember.name+"."+props.extension
    - component: f7-row
      slots:
        default:
          - component: oh-repeater
            config:
              filter: true
              for: familyMember
              fragment: true
              groupItem: =props.family
              sourceType: itemsInGroup
            slots:
              default:
                - component: f7-col
                  slots:
                    default:
                      - component: Label
                        config:
                          class:
                            - text-align-center
                          style:
                            color: =items[loop.familyMember.name].state=="ON"?"green":"grey"
                            font-size: 15px
                            text-shadow: 2px 2px rgba(80,80,80,.15)
                          text: =loop.familyMember.label
    - component: f7-row
      config:
        style:
          display: =(items[props.notFamily].state=="ON")?"":"none"
      slots:
        default:
          - component: f7-col
            slots:
              default:
                - component: Label
                  config:
                    style:
                      font-size: 15px
                      font-weight: bold
                      padding-left: 15px
                      padding-top: 15px
                      text-shadow: 2px 2px rgba(80,80,80,.15)
                    text: =props.visitorsTitle
    - component: f7-row
      config:
        style:
          display: =(items[props.notFamily].state=="ON")?"":"none"
      slots:
        default:
          - component: f7-col
            slots:
              default:
                - component: oh-list
                  slots:
                    default:
                      - component: oh-repeater
                        config:
                          filter: loop.person.state == "ON"
                          for: person
                          groupItem: =props.notFamily
                          sourceType: itemsInGroup
                        slots:
                          default:
                            - component: oh-list-item
                              config:
                                action: analyzer
                                actionAnalyzerItems:
                                  - =loop.person.name
                                icon: f7:person_alt
                                iconColor: green
                                item: =loop.person.name
                                style:
                                  padding-left: 10px
                                title: =loop.person.label

You will need a switch item that indicates if a person is at home for every person you want to appear in the widget.
You will need a group (defined as switch, with OR) in which you will put your family members and another one for visitors.
You need every person’s name in the item label.
You will need an image for each family member in the html folder inside the openHAB configuration folder, named just like the switch items. If you don’t want to create a folder inside the html folder for these images, specify a white space (" ") in the widget configuration.

For example, to get the results of the image you need these groups and items:

Group:Switch:OR(ON, OFF) FakeFamily "Fake family [%d]"
Switch Alfred "Alfred" <presence> (FakeFamily) //ON
Switch Betty "Betty" <presence> (FakeFamily) //ON
Switch Cassandra "Cassandra" <presence> (FakeFamily) //OFF
Switch Daisy "Daisy" <presence> (FakeFamily) //OFF

Group:Switch:OR(ON, OFF) FakeNotFamily "Fake not family [%d]"
Switch Edgard "Edgard" <presence> (FakeNotFamily) //OFF
Switch Finn "Finn" <presence> (FakeNotFamily) //ON
Switch Gabriel "Gabriel" <presence> (FakeNotFamily) //OFF
Switch Henry "Henry" <presence> (FakeNotFamily) //ON
Switch Isabella "Isabella" <presence> (FakeNotFamily) //ON

And you will need four .png images: Alfred.png, Betty.png Cassandra.png and Daisy.png. These will go to a “presence” folder I created in the html folder inside the openHAB configuration folder. In my case it is /etc/openhab/html/presence:

$ ls /etc/openhab/html/presence
Alfred.png  Betty.png  Cassandra.png  Daisy.png

You will then configure the widget like this:


image

Share a screenshot if you like it!
Regards.

Edit: Fixed visitors names not visible until reloading and a little restyling.

8 Likes

Hi all,

I configured everything according to the description here.
Unfortunately my pictures are not displayed, instead I get broken images back.

I have placed the images under /etc/openhab/html/presence/.
If I try to access the pictures directly in the browser via http://IPOFMYOPENHAB:8080/static/presence/Manuel.png I get a 403 forbidden. Do I need to change read permissions via chmod to above directory or something? If so, what exactly do I need to change?

Furthermore, for testing purpose, I moved the images to /etc/openhab/html/ and I am then able to access them via my browser (http://IPOFMYOPENHAB:8080/static/Manuel.png). Even though I configured the subfolder int the widget as described as a whitespace (" ") I still get it displayed as broken images.

Can somebody help?

Cheers,
Manuel

Hi,
It seems the permissions for the images are correct, because openHAB can access them at the static folder. But, can the openhab user (or the one you are using to run openHAB access the presence folder? You can grant permissions to everybody with:

sudo chmod a+rw /etc/openhab/html/presence/

Anyway, I don’t know why your test is failing. If you right click on the broken image and choose “Open image in new tab” (in Chrome), what is it trying to load?
Regards.

@jjmeseguer how do you “detect” that a person is home/present? Also how do you do that with visitors?

Hi,
I do it by tracking DHCP requests, more or less as explained here:

I have my own DHCP server. I assign fixed IP addresses there to the phones of those who I want to track (family or visitors). When something connects to the network, the DHCP server tells openHAB through the API.
Regards.

1 Like

@jjmeseguer: Man, you fixed it for me!
The mistake i did was naming the image “Manuel.png” while only the label of the switch was set to “Manuel”, but not the name of the switch. So the widget looked for the name and - of course - could not find an image in the respective folder.
I now moved the files again in the subfolder presence and it works fine without adapting directory permissions on the server itself.
Thank you so much!

Just struggling now with some compatibility issues. While the images are displayed in true colors on Samsung Internet on my mobile and edge on the PC when present, Mozilla shows the images always in grey. Is this known?

Glad you got it to work!
But I’m afraid I can’t help you with the colors. I’ve tested it on Chrome and Firefox on Windows, Chrome, Firefox and Edge on Linux, Safari and openHAB app on iOS and Samsung Internet, Mozilla Firefox and openHAB app on Android (Samsung S22), and I’m always getting the images in color correctly.

Hi all
I have a issue with the .png images not displaying and i believe it has something to do with the image folder location
I run a windows machine and i see that most of the comments relate to Linux machines is there a need to write the path in a different format ???
Currently it is as follows C:\OpenHAB3\conf\html\presence which is where the.png files are located

Thanks Geoff

Hi,
The widget takes the images from the web server, so it should always be in Linux format.
In your case, you should just type “presence”, as in the example.
Regards.

Thanks for the reply
I have done that but i am still not getting the images as seen below
image

The presence folder is located in the following path C:\OpenHAB3\conf\html\presence and the images are as follows
image


i hope this makes sense and any help would be appreciated

Geoff

If you right click on one of the broken images and open it in a new tab, what do you get? What is the address of the image it is trying to download?

Thank got it working had the images named wrong

thanks for you help

geoff

Hi @jjmeseguer,

Unfortunately and ironically, my openhab crashed fatally when I was in the process of implementing a backup routine. Therefore, I am currently reconfiguring everything.
When installing the UI widget, I now get an error message in my log. This only happens for the at home Card. Other widgets work:

[ERROR] [munity.CommunityUIWidgetAddonHandler] - Widget from marketplace is invalid: Couldn't find the widget in the add-on entry

While searching for a solution I came across the following thread in the forum.

Not sure, if this is really the root cause, as it worked last time pretty well and I am not aware, you changed something meanwhile, but I wanted to share with you anyway.

Best,
Manuel

Hi,
It was already as mentioned in that post, but I have removed the spaces in the uid, which are not allowed in the last openHAB version. Please, try again.
Regards.

Thank you for checking up on it.
Unfortunately it still gives the same error log.

If it works for all the others I might try on a clean install. Potentially this may be related to a restore I did meanwhile (widget was installed and a non-full backup was made with “at home Card” 50% configured - later the backup was restored on a fresh install without having “at home Card” installed before the restore).

Hi,
I don’t know what it can be the, I’m sorry. Try to copy/paste the yaml code in Developer tools/Widgets as a new widget (maybe you’ll have to change the uid).
Regards.

Hi,

do you now how I can print a datetime timestamp below the name with colorchange?

Best regards
Martin

Hi,
Sorry for the late response.
Yes you can. Suppose the items where you have the datetime timestamp are named just like the items that indicate if family members are at home with “Timestamp” concatenated at the end. For example, if the item for presence is “Alfred”, the datetime timestamp item should be “AlfredTimestamp”.
At line 149, just after “text: =loop.familyMember.label”, you should insert:

    - component: f7-row
      slots:
        default:
          - component: oh-repeater
            config:
              filter: true
              for: familyMember
              fragment: true
              groupItem: =props.family
              sourceType: itemsInGroup
            slots:
              default:
                - component: f7-col
                  slots:
                    default:
                      - component: Label
                        config:
                          class:
                            - text-align-center
                          style:
                            color: rgba(50,50,50,1)
                            font-size: 12px
                            text-shadow: 2px 2px rgba(80,80,80,.15)
                          text: =items[loop.familyMember.name+"Timestamp"].state

You should see the contents of the DateTime items below the names. The color will be dark gray (rgba(50,50,50,1)).
Best regards.

Hi, it works, Thank you very much…

Best regards,
Martin