wonderslug / MMM-HomeAssistantDisplay

A Magic Mirror Module to display information from Home Assistant.
MIT License
83 stars 6 forks source link

HA sensor state not refreshing on MM module #17

Closed uros76 closed 1 year ago

uros76 commented 1 year ago

Hi. Thanks for a great module :).

I can see the HA sensor state displayed correctly but if the state changes this does not get updated on my MM. After I restart the MM the correct state shows up. Am I missing something or doing it wrong? 🤷‍♂️

Here is my module code in the MM config:

{
    module: 'MMM-HomeAssistantDisplay',
    position: 'bottom_center',
    config: {
        host: "192.168.1.226",
        token: "hidden",
        port: 8123,
        title: "HA inputs",
        sections: [{
            triggerEntities: [
                "states.lock.front_door_2.state"
            ],
                displayTemplate: `
                {%- if states.lock.front_door_2.state == "locked" -%}
                {%- set icon = "home-lock" -%}
                {%- set stateText = "Locked" -%}
                {%- elif states.lock.front_door_2.state == "unlocked" -%}
                {%- set icon = "home-lock-open" -%}
                {%- set stateText = "Unlocked" -%}
                {%- endif -%}
                <i class='mdi mdi-{{icon}}'></i> Front door - {{stateText}}
                `,
        }]
    },
},
wonderslug commented 1 year ago

Hey. glad you like.

you have the trigger entity as "states.lock.front_door_2.state" should just be lock.front_door_2

uros76 commented 1 year ago

Oh boy, now I am ashamed of this tiny mistake 😒. It works of course, thanks a lot! 👍😊

wonderslug commented 1 year ago

No problem. Easy mistake to make.

uros76 commented 1 year ago

@wonderslug I have another refresh related question.

The entity state change does get refreshed on the MM module but the relative time of last_updated does not get refreshed. Do I need to specify something extra to get the time of change refreshed on the MM? On the HA templating it works, relative time gets updated on it's own.

Here is the updated test code currently in use:

{
    module: 'MMM-HomeAssistantDisplay',
    position: 'bottom_center',
    config: {
        host: "192.168.1.226",
        token: "hidden$
        port: 8123,
        title: "HA inputs",
        sections: [{
            triggerEntities: [
                "lock.front_door_2"
            ],
                displayTemplate: `
                {%- if states.lock.front_door_2.state == "locked" -%}
                {%- set icon = "home-lock" -%}
                {%- set stateText = "Locked" -%}
                {%- elif states.lock.front_door_2.state == "unlocked" -%}
                {%- set icon = "home-lock-open" -%}
                {%- set stateText = "Unlocked" -%}
                {%- endif -%}
                <i class='mdi mdi-{{icon}}'></i> Front door - {{stateText}} {{relative_time(states.lock.front_door_2.last_updated)}} ago
                `,
        }]
    },
},
wonderslug commented 1 year ago

So the display template is fully rendered by Home Assistant itself. Im not sure whats going on with the last updated but you can check your displayTemplate using the Developer Tools Template renderer. You should be able to see exactly what the output of the display template is going to be.

Open your Home Assistant instance and show your template developer tools.

uros76 commented 1 year ago

So the display template is fully rendered by Home Assistant itself. Im not sure whats going on with the last updated but you can check your displayTemplate using the Developer Tools Template renderer. You should be able to see exactly what the output of the display template is going to be.

Open your Home Assistant instance and show your template developer tools.

Tried it and the relative time works correctly, it gets updated in the output. The icon doesn't get processed but that's normal for an alphanumerical renderer. image

uros76 commented 1 year ago

I might end up just using the fixed time of the last update state. Relative processed time somehow doesn't work 🤷‍♂️.