Script not Working - Getting Temp from a Sensor  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
SiberianTiger
Posts: 2
Joined: Monday 28 September 2020 21:41
Target OS: NAS (Synology & others)
Domoticz version: 2020.1
Location: Switzerland
Contact:

Script not Working - Getting Temp from a Sensor

Post by SiberianTiger »

Hi Guys (and Girls?)

I have a "MyStrom" Switch with integrated Temp-Sensor. I would like to get that Data from the Switch and pass it to a Virtual Sensor in Domoticz.

MyStrom Switch API: https://api.mystrom.ch/#982cf1bb-c873-4 ... dfa51e1afe

I have created a Dummy and a Virtual Temperatur Sensor called "Temp Balkon"

Then i searched trough the wiki an came out with this Script below:
It doesn't give me an error in the log, but also the Temperatur does not get Updated it shows only 0°C.
The Output of the Integrated Sensor looks like this:

Code: Select all

{"measured":21.3125,"compensation":11,"compensated":10.3125}
My Script to get the Data is that:

Code: Select all

return {
	on = {
		timer = {
			'every 5 seconds' -- just an example to trigger the request
		},
		httpResponses = {
			'TempBalkon' -- must match with the callback passed to the openURL command
		}
	},
	execute = function(domoticz, item)

		if (item.isTimer) then
			domoticz.openURL({
				url = 'xxx.xxx.xxx.xxx',
				method = 'GET /temp',
				callback = 'TempBalkon', -- see httpResponses above.
			})
		end

		if (item.isHTTPResponse) then

			if (item.ok) then
				if (item.isJSON) then

					local TempBalkon = item.json.compensated  -- just an example

					-- update some device in Domoticz
					domoticz.devices('TempBalkon').updatetemperatur(item.json.compensated)
				end
			else
				domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
				domoticz.log(item, domoticz.LOG_ERROR)
			end

		end

	end
}
What did i wrong? Sorry im new to this whole scripting thing, but i tought that i could make this with reading trought the Wiki...

Thanks in Advance
Last edited by SiberianTiger on Monday 28 September 2020 23:24, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Script not Working - Getting Temp from a Sensor

Post by waaren »

SiberianTiger wrote: Monday 28 September 2020 22:14 Then i searched trough the wiki an came out with this Script below:
It doesn't give me an error in the log, but also the Temperatur does not get Updated it shows only 0°C.

What did i wrong? Sorry im new to this whole scripting thing, but i tought that i could make this with reading trought the Wiki...
See my remarks in below script.

Code: Select all

return
{
    on =
    {
        timer =
        {
            'every minute', -- timer can not be set to a higher frequency then once a minute.
        },

        httpResponses =
        {
            'TempBalkon', -- must match with the callback passed to the openURL command
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when all ok
        marker = 'Balcony temperature',
    },

    execute = function(domoticz, item)

        if item.isTimer then
            domoticz.openURL(
            {
                url = '192.168.178.30',
                method = 'GET', -- methods can only be GET, POST, PUT and DELETE
                callback = 'TempBalkon', -- see httpResponses above.
            })
        elseif item.isHTTPResponse then
            if item.ok and item.isJSON then
                    local TempBalkon = item.json.compensated  -- just an example

                    -- update some device in Domoticz
                    domoticz.devices('TempBalkon').updateTemperature(item.json.compensated) -- methods are case sensitive
            else
                domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
                domoticz.log(item, domoticz.LOG_DEBUG)
            end
        else
            domoticz.log('Kind of unexpected..', domoticz.LOG_ERROR)
            domoticz.log(item, domoticz.LOG_DEBUG)
        end

    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
SiberianTiger
Posts: 2
Joined: Monday 28 September 2020 21:41
Target OS: NAS (Synology & others)
Domoticz version: 2020.1
Location: Switzerland
Contact:

Re: Script not Working - Getting Temp from a Sensor  [Solved]

Post by SiberianTiger »

Perfect! Simply Perfect! Thanks Man... With your Tips and the Error log i found the Problems!

The now working script is this:

Code: Select all

return
{
    on =
    {
        timer =
        {
            'every minute', -- timer can not be set to a higher frequency then once a minute.
        },

        httpResponses =
        {
            'TempBalkon', -- must match with the callback passed to the openURL command
        },
    },

    logging =
    {
        level = domoticz.LOG_ERROR, -- change to domoticz.LOG_ERROR when all ok
        marker = 'Balcony temperature',
    },

    execute = function(domoticz, item)

        if item.isTimer then
            domoticz.openURL(
            {
                url = 'xxx.xxx.xxx.xxx/temp',
                method = 'GET', -- methods can only be GET, POST, PUT and DELETE
                callback = 'TempBalkon', -- see httpResponses above.
            })
        elseif item.isHTTPResponse then
            if item.ok and item.isJSON then
                    local TempBalkon = item.json.compensated  -- just an example

                    -- update some device in Domoticz
                    domoticz.devices(17).updateTemperature(item.json.compensated) -- methods are case sensitive
            else
                domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
                domoticz.log(item, domoticz.LOG_DEBUG)
            end
        else
            domoticz.log('Kind of unexpected..', domoticz.LOG_ERROR)
            domoticz.log(item, domoticz.LOG_DEBUG)
        end

    end
}
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest