Generic energy meter & Magic

Hello,
I had these things working before, but after a reset and reinstall, I can’t figure it out why the generic energy meter is showing nothing. More precise, I got an energy sensor that publish mqtt json: {“power”:1.05,“curr”:4.77}
I’ve defined in Magic a MQTT client power that receives the mqtts:

ThingEvent {
thingId: “{ac48440b-596a-4d16-9004-130df6bb2c2e}” // MQTT client power
eventName: “triggered”
onTriggered: {
var pwr = JSON.parse(params[“data”])
power.value = pwr.power
console.log("Power: ", power.value, ", ", pwr.power )
}
}
Also, I’ve put a thing state
ThingState {
id:power
thingId: “{db36a37d-7c48-4208-8b6e-a1b93acb827f}” // Generic energy meter power state
stateName: “currentPower”
}

But all I’ve got in Console is undefined error for power.value:
89: Power: undefined , 2.17

What am I doing wrong?
Thank you.

Can’t spot an obvious mistake right now. Can you paste the entire script?

import QtQuick 2.0
import nymea 1.0

Item {
        id:root
        property int counter:0
        property bool startup: true
        property bool net: true
        
        
        ThingEvent {
            thingId: "{ee36061a-5c6f-4e17-9187-7a0cceefa978}" // MQTT client tdevext
           eventName: "triggered"
            onTriggered: {
                var r2_temp = JSON.parse(params["data"])
                tempext.value = (1.0 * r2_temp.temp + 20)/70
            }
        }    
    
        ThingState {
            id:tempext
            thingId: "{1fe10414-280f-4a2b-9ae9-56c69f3ac135}" // Senzor exterior
            stateName: "input"
        }
        
        ThingEvent {
            thingId: "{ebbc06f7-e6be-4e1c-ac03-51d4a66bb056}" // MQTT client tdev1
            eventName: "triggered"
            onTriggered: {
                var r2_temp = JSON.parse(params["data"])
                temp1.value = (1.0 * r2_temp.temp + 20)/70
            }
        }    
        
        ThingState {
            id:temp1
            thingId: "{61ac8ce6-a415-4c4a-8ddb-2f5f93c782b5}" // Senzor Helinke
            stateName: "input"
        }
        
        ThingEvent {
            thingId: "{0212bc8c-9155-4828-b07d-93bbc59b822d}" // MQTT client tdev2
            eventName: "triggered"
            onTriggered: {
                var r2_temp = JSON.parse(params["data"])
                temp2.value = (1.0 * r2_temp.temp + 20)/70
            }
        }           
    
        ThingState {
            id:temp2
            thingId: "{e92c765c-2178-42c3-80be-62dc2f53ae16}" // Senzor Flavius
            stateName: "input"
        }
        
         ThingEvent {
            thingId: "{625bd702-428c-4c03-b76c-b9c03c648433}" // MQTT client tdev3
            eventName: "triggered"
            onTriggered: {
                var r2_temp = JSON.parse(params["data"])
                temp3.value = (1.0 * r2_temp.temp + 20)/70
            }
        }           
    
        ThingState {
            id:temp3
            thingId: "{3b78ba93-cd0c-4ab1-b913-f7599affc1ca}" // Senzor sufragerie
            stateName: "input"
        }
       
       ThingState {
            id:energy 
            thingId: "{db36a37d-7c48-4208-8b6e-a1b93acb827f}" // Consum energie
            stateName: "totalEnergyConsumed"
       }

        ThingState {
            id:power
            thingId: "{5a083458-e476-487d-ab8f-75e92cf16489}" // Generic energy meter
            stateName: "currentPower"
       }
        
        ThingEvent {
            thingId: "{ac48440b-596a-4d16-9004-130df6bb2c2e}" // MQTT client power
            eventName: "triggered"
            onTriggered: {
                var pwr = JSON.parse(params["data"])
                power.value = pwr.power
                console.log("Power: ",power.value, ", ", pwr.power )
            }
       }   

}

If I change power.value = pwr.power with temp3.value = pwr.power, the console.log shows me Power: 0.45 , 0.45
It’s like the power id thing state is not recognized.
I even tried to rename the id of thing state from power to something else, but had no luck either.

The only thing I can imagine is, that maybe the thing ID is not valid. That would cause such a message. Can you verify it’s the correct one?

I’ve added some more useful debug prints to the script console in such cases: Add more debug prints to script console when ThingState fails by mzanetti · Pull Request #659 · nymea/nymea · GitHub

Well, looks like it was my mistake, but thank you for involvement Michael.
The problem was with the thingID, more precisely, the generic energy meter has an ID, but also the generic energy meter has a few ThingStates, each one of them with its own id.
I used the ID of the thingstate (currentPower) instead of the generic energy meter 's ID.

Off topic request: is it possible to increase the font size in magic scripts? Or is a method (unknown for me) to increase the size?

Glad it’s working now. Next experimental build should help better with finding such mistakes.

You can zoom in/out with ctrl + +/-