create DzVents script based on Smoke Alarm Fibaro Smoke 2  [Solved]

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

Moderator: leecollings

User avatar
Ragdag
Posts: 147
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

create DzVents script based on Smoke Alarm Fibaro Smoke 2

Post by Ragdag »

I have several Fibaro Smoke Sensors, and I am using those as temperature sensor.

I'm looking into if it is possible to kick of a DzVents script based on a smoke alarm

When I manuall trigger the sensor I see this in the logs

Code: Select all

2020-06-02 13:45:41.671 (Z-wave) General/Alarm (Alarm Type: Smoke Alarm 1 (0x01))
2020-06-02 13:45:41.684 (Z-wave) Light/Switch (Smoke Alarm)
2020-06-02 13:45:41.668 Status: OpenZWave: Alarm received (Smoke Alarm: Smoke Test), NodeID: 12 (0x0c)
2020-06-02 13:45:53.681 (Z-wave) General/Alarm (Alarm Type: Smoke Alarm 1 (0x01))
2020-06-02 13:45:53.688 (Z-wave) Light/Switch (Smoke Alarm)
2020-06-02 13:45:53.674 Status: OpenZWave: Alarm received (Smoke Alarm: Clear), NodeID: 12 (0x0c)
Also I see these Devices under the Sensor
Image

Is there a way to pick up Alarm Type: Smoke Alarm 1 (0x01) in DzVents?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: create DzVents script based on Smoke Alarm Fibaro Smoke 2

Post by waaren »

Ragdag wrote: Tuesday 02 June 2020 14:04 I have several Fibaro Smoke Sensors, and I am using those as temperature sensor.
I'm looking into if it is possible to kick of a DzVents script based on a smoke alarm
Is there a way to pick up Alarm Type: Smoke Alarm 1 (0x01) in DzVents?
I don't know for sure but you can use below script to check what devices are picked up by dzVents.

Code: Select all

local myAlarm = { 319,320,320,321,322,323,324,325,326,327}
return 
{
    on = 
    {
        devices = myAlarm,
    },

    logging =
    {
        level = domoticz.LOG_INFO,
    },

    execute = function(dz, item)
        dz.log('Device ' .. item.name .. ' (' .. item.idx .. ') triggered this script', dz.LOG_INFO)
        
        for _, idx in ipairs(myAlarm) do
            local device = dz.devices(idx)
            if dz.utils.deviceExists(idx) then
                dz.log('Device ' .. device.name .. ' (' .. device.idx .. ') state: ' .. device.state .. '; last Updated: ' .. device.lastUpdate.rawDateTime, dz.LOG_INFO)
            end
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
Ragdag
Posts: 147
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: create DzVents script based on Smoke Alarm Fibaro Smoke 2

Post by Ragdag »

I would probably need to add them all first right?
Only Temp is added at the moment
Image

After that I would need to trigger another smoke alarm?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: create DzVents script based on Smoke Alarm Fibaro Smoke 2

Post by waaren »

Ragdag wrote: Tuesday 02 June 2020 16:10 I would probably need to add them all first right?
Yes. ( They are easy to inactivate afterwards if / when no longer needed.)
After that I would need to trigger another smoke alarm?
Yes
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
Ragdag
Posts: 147
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: create DzVents script based on Smoke Alarm Fibaro Smoke 2

Post by Ragdag »

That does give us some insight :)

Code: Select all

2020-06-02 16:35:54.115 (Z-wave) General/Alarm (Alarm Type: Smoke Alarm 1 (0x01))
2020-06-02 16:35:54.132 (Z-wave) Light/Switch (Smoke Alarm) 
2020-06-02 16:35:54.284 Status: dzVents: Info: ------ Start internal script: DZ_Test: Device: "Alarm Type: Smoke Alarm 1 (0x01) (Z-wave)", Index: 326
2020-06-02 16:35:54.284 Status: dzVents: Info: Device Alarm Type: Smoke Alarm 1 (0x01) (326) triggered this script
2020-06-02 16:35:54.285 Status: dzVents: Info: Device Temp Overloop (185) state: 26.1; last Updated: 2020-06-02 16:22:23
2020-06-02 16:35:54.286 Status: dzVents: Info: Device Sensor (319) state: Off; last Updated: 2020-06-02 13:56:44
2020-06-02 16:35:54.287 Status: dzVents: Info: Device Smoke Alarm (320) state: Off; last Updated: 2020-06-02 13:56:44
2020-06-02 16:35:54.287 Status: dzVents: Info: Device Smoke Alarm (320) state: Off; last Updated: 2020-06-02 13:56:44
2020-06-02 16:35:54.288 Status: dzVents: Info: Device Heat (321) state: Off; last Updated: 2020-06-02 13:54:20
2020-06-02 16:35:54.289 Status: dzVents: Info: Device Home Security (322) state: On; last Updated: 2020-06-02 13:54:19
2020-06-02 16:35:54.290 Status: dzVents: Info: Device Power Management (323) state: Off; last Updated: 2020-06-02 13:45:00
2020-06-02 16:35:54.291 Status: dzVents: Info: Device System (324) state: Off; last Updated: 2020-06-02 13:45:00
2020-06-02 16:35:54.292 Status: dzVents: Info: Device General (325) state: On; last Updated: 2020-06-02 13:54:20
2020-06-02 16:35:54.292 Status: dzVents: Info: Device Alarm Type: Smoke Alarm 1 (0x01) (326) state: Smoke Test; last Updated: 2020-06-02 13:56:44
2020-06-02 16:35:54.293 Status: dzVents: Info: Device Alarm Type: Home Security 7 (0x07) (327) state: Tampering - Cover Removed; last Updated: 2020-06-02 13:54:19
2020-06-02 16:35:54.293 Status: dzVents: Info: ------ Finished DZ_Test
2020-06-02 16:35:54.387 Status: dzVents: Info: ------ Start internal script: DZ_Test: Device: "Smoke Alarm (Z-wave)", Index: 320
2020-06-02 16:35:54.387 Status: dzVents: Info: Device Smoke Alarm (320) triggered this script
2020-06-02 16:35:54.388 Status: dzVents: Info: Device Temp Overloop (185) state: 26.1; last Updated: 2020-06-02 16:22:23
2020-06-02 16:35:54.389 Status: dzVents: Info: Device Sensor (319) state: Off; last Updated: 2020-06-02 13:56:44
2020-06-02 16:35:54.389 Status: dzVents: Info: Device Smoke Alarm (320) state: On; last Updated: 2020-06-02 13:56:44
2020-06-02 16:35:54.389 Status: dzVents: Info: Device Smoke Alarm (320) state: On; last Updated: 2020-06-02 13:56:44
2020-06-02 16:35:54.390 Status: dzVents: Info: Device Heat (321) state: Off; last Updated: 2020-06-02 13:54:20
2020-06-02 16:35:54.391 Status: dzVents: Info: Device Home Security (322) state: On; last Updated: 2020-06-02 13:54:19
2020-06-02 16:35:54.392 Status: dzVents: Info: Device Power Management (323) state: Off; last Updated: 2020-06-02 13:45:00
2020-06-02 16:35:54.393 Status: dzVents: Info: Device System (324) state: Off; last Updated: 2020-06-02 13:45:00
2020-06-02 16:35:54.394 Status: dzVents: Info: Device General (325) state: On; last Updated: 2020-06-02 13:54:20
2020-06-02 16:35:54.395 Status: dzVents: Info: Device Alarm Type: Smoke Alarm 1 (0x01) (326) state: Smoke Test; last Updated: 2020-06-02 16:35:54
2020-06-02 16:35:54.395 Status: dzVents: Info: Device Alarm Type: Home Security 7 (0x07) (327) state: Tampering - Cover Removed; last Updated: 2020-06-02 13:54:19
2020-06-02 16:35:54.396 Status: dzVents: Info: ------ Finished DZ_Test
2020-06-02 16:35:54.396 Status: dzVents: Info: ------ Start internal script: DZ_Test: Device: "Smoke Alarm (Z-wave)", Index: 320
2020-06-02 16:35:54.396 Status: dzVents: Info: Device Smoke Alarm (320) triggered this script
2020-06-02 16:35:54.396 Status: dzVents: Info: Device Temp Overloop (185) state: 26.1; last Updated: 2020-06-02 16:22:23
2020-06-02 16:35:54.396 Status: dzVents: Info: Device Sensor (319) state: Off; last Updated: 2020-06-02 13:56:44
2020-06-02 16:35:54.396 Status: dzVents: Info: Device Smoke Alarm (320) state: On; last Updated: 2020-06-02 13:56:44
2020-06-02 16:35:54.396 Status: dzVents: Info: Device Smoke Alarm (320) state: On; last Updated: 2020-06-02 13:56:44
2020-06-02 16:35:54.396 Status: dzVents: Info: Device Heat (321) state: Off; last Updated: 2020-06-02 13:54:20
2020-06-02 16:35:54.396 Status: dzVents: Info: Device Home Security (322) state: On; last Updated: 2020-06-02 13:54:19
2020-06-02 16:35:54.396 Status: dzVents: Info: Device Power Management (323) state: Off; last Updated: 2020-06-02 13:45:00
2020-06-02 16:35:54.396 Status: dzVents: Info: Device System (324) state: Off; last Updated: 2020-06-02 13:45:00
2020-06-02 16:35:54.396 Status: dzVents: Info: Device General (325) state: On; last Updated: 2020-06-02 13:54:20
2020-06-02 16:35:54.396 Status: dzVents: Info: Device Alarm Type: Smoke Alarm 1 (0x01) (326) state: Smoke Test; last Updated: 2020-06-02 16:35:54
2020-06-02 16:35:54.396 Status: dzVents: Info: Device Alarm Type: Home Security 7 (0x07) (327) state: Tampering - Cover Removed; last Updated: 2020-06-02 13:54:19
2020-06-02 16:35:54.396 Status: dzVents: Info: ------ Finished DZ_Test
2020-06-02 16:35:57.696 (Power-Gas) P1 Smart Meter (kWh Totaal)
2020-06-02 16:36:07.699 (Power-Gas) P1 Smart Meter (kWh Totaal)
2020-06-02 16:36:15.314 (Z-wave) Light/Switch (Sensor)
2020-06-02 16:36:15.330 (Z-wave) General/Alarm (Alarm Type: Smoke Alarm 1 (0x01))
2020-06-02 16:36:15.345 (Z-wave) Light/Switch (Smoke Alarm)
2020-06-02 16:36:15.690 (Z-wave) Temp (Temp Overloop)
2020-06-02 16:36:15.307 Status: OpenZWave: Alarm received (Smoke Alarm: Clear), NodeID: 12 (0x0c)
2020-06-02 16:36:15.453 Status: dzVents: Info: ------ Start internal script: DZ_Test: Device: "Sensor (Z-wave)", Index: 319
2020-06-02 16:36:15.453 Status: dzVents: Info: Device Sensor (319) triggered this script
2020-06-02 16:36:15.454 Status: dzVents: Info: Device Temp Overloop (185) state: 26.1; last Updated: 2020-06-02 16:22:23
2020-06-02 16:36:15.454 Status: dzVents: Info: Device Sensor (319) state: Off; last Updated: 2020-06-02 13:56:44
2020-06-02 16:36:15.455 Status: dzVents: Info: Device Smoke Alarm (320) state: On; last Updated: 2020-05-25 19:20:50
2020-06-02 16:36:15.455 Status: dzVents: Info: Device Smoke Alarm (320) state: On; last Updated: 2020-05-25 19:20:50
2020-06-02 16:36:15.456 Status: dzVents: Info: Device Heat (321) state: Off; last Updated: 2020-06-02 13:54:20
2020-06-02 16:36:15.457 Status: dzVents: Info: Device Home Security (322) state: On; last Updated: 2020-06-02 13:54:19
2020-06-02 16:36:15.458 Status: dzVents: Info: Device Power Management (323) state: Off; last Updated: 2020-06-02 13:45:00
2020-06-02 16:36:15.459 Status: dzVents: Info: Device System (324) state: Off; last Updated: 2020-06-02 13:45:00
2020-06-02 16:36:15.459 Status: dzVents: Info: Device General (325) state: On; last Updated: 2020-06-02 13:54:20
2020-06-02 16:36:15.460 Status: dzVents: Info: Device Alarm Type: Smoke Alarm 1 (0x01) (326) state: Smoke Test; last Updated: 2020-06-02 16:35:54
2020-06-02 16:36:15.461 Status: dzVents: Info: Device Alarm Type: Home Security 7 (0x07) (327) state: Tampering - Cover Removed; last Updated: 2020-06-02 13:54:19
2020-06-02 16:36:15.461 Status: dzVents: Info: ------ Finished DZ_Test
2020-06-02 16:36:15.558 Status: dzVents: Info: ------ Start internal script: DZ_Test: Device: "Smoke Alarm (Z-wave)", Index: 320
2020-06-02 16:36:15.558 Status: dzVents: Info: Device Smoke Alarm (320) triggered this script
2020-06-02 16:36:15.559 Status: dzVents: Info: Device Temp Overloop (185) state: 26.1; last Updated: 2020-06-02 16:22:23
2020-06-02 16:36:15.560 Status: dzVents: Info: Device Sensor (319) state: Off; last Updated: 2020-05-24 16:31:46
2020-06-02 16:36:15.560 Status: dzVents: Info: Device Smoke Alarm (320) state: Off; last Updated: 2020-05-25 19:20:50
2020-06-02 16:36:15.561 Status: dzVents: Info: Device Smoke Alarm (320) state: Off; last Updated: 2020-05-25 19:20:50
2020-06-02 16:36:15.561 Status: dzVents: Info: Device Heat (321) state: Off; last Updated: 2020-06-02 13:54:20
2020-06-02 16:36:15.562 Status: dzVents: Info: Device Home Security (322) state: On; last Updated: 2020-06-02 13:54:19
2020-06-02 16:36:15.563 Status: dzVents: Info: Device Power Management (323) state: Off; last Updated: 2020-06-02 13:45:00
2020-06-02 16:36:15.564 Status: dzVents: Info: Device System (324) state: Off; last Updated: 2020-06-02 13:45:00
2020-06-02 16:36:15.565 Status: dzVents: Info: Device General (325) state: On; last Updated: 2020-06-02 13:54:20
2020-06-02 16:36:15.566 Status: dzVents: Info: Device Alarm Type: Smoke Alarm 1 (0x01) (326) state: Clear; last Updated: 2020-06-02 16:35:54
2020-06-02 16:36:15.567 Status: dzVents: Info: Device Alarm Type: Home Security 7 (0x07) (327) state: Tampering - Cover Removed; last Updated: 2020-06-02 13:54:19
2020-06-02 16:36:15.567 Status: dzVents: Info: ------ Finished DZ_Test
2020-06-02 16:36:15.567 Status: dzVents: Info: ------ Start internal script: DZ_Test: Device: "Smoke Alarm (Z-wave)", Index: 320
2020-06-02 16:36:15.567 Status: dzVents: Info: Device Smoke Alarm (320) triggered this script
2020-06-02 16:36:15.567 Status: dzVents: Info: Device Temp Overloop (185) state: 26.1; last Updated: 2020-06-02 16:22:23
2020-06-02 16:36:15.567 Status: dzVents: Info: Device Sensor (319) state: Off; last Updated: 2020-05-24 16:31:46
2020-06-02 16:36:15.567 Status: dzVents: Info: Device Smoke Alarm (320) state: Off; last Updated: 2020-05-25 19:20:50
2020-06-02 16:36:15.567 Status: dzVents: Info: Device Smoke Alarm (320) state: Off; last Updated: 2020-05-25 19:20:50
2020-06-02 16:36:15.567 Status: dzVents: Info: Device Heat (321) state: Off; last Updated: 2020-06-02 13:54:20
2020-06-02 16:36:15.567 Status: dzVents: Info: Device Home Security (322) state: On; last Updated: 2020-06-02 13:54:19
2020-06-02 16:36:15.567 Status: dzVents: Info: Device Power Management (323) state: Off; last Updated: 2020-06-02 13:45:00
2020-06-02 16:36:15.567 Status: dzVents: Info: Device System (324) state: Off; last Updated: 2020-06-02 13:45:00
2020-06-02 16:36:15.568 Status: dzVents: Info: Device General (325) state: On; last Updated: 2020-06-02 13:54:20
2020-06-02 16:36:15.568 Status: dzVents: Info: Device Alarm Type: Smoke Alarm 1 (0x01) (326) state: Clear; last Updated: 2020-06-02 16:35:54
2020-06-02 16:36:15.568 Status: dzVents: Info: Device Alarm Type: Home Security 7 (0x07) (327) state: Tampering - Cover Removed; last Updated: 2020-06-02 13:54:19
2020-06-02 16:36:15.568 Status: dzVents: Info: ------ Finished DZ_Test
2020-06-02 16:36:15.568 Status: dzVents: Info: ------ Start internal script: DZ_Test: Device: "Alarm Type: Smoke Alarm 1 (0x01) (Z-wave)", Index: 326
2020-06-02 16:36:15.568 Status: dzVents: Info: Device Alarm Type: Smoke Alarm 1 (0x01) (326) triggered this script
2020-06-02 16:36:15.568 Status: dzVents: Info: Device Temp Overloop (185) state: 26.1; last Updated: 2020-06-02 16:22:23
2020-06-02 16:36:15.568 Status: dzVents: Info: Device Sensor (319) state: Off; last Updated: 2020-05-24 16:31:46
2020-06-02 16:36:15.568 Status: dzVents: Info: Device Smoke Alarm (320) state: Off; last Updated: 2020-05-25 19:20:50
2020-06-02 16:36:15.568 Status: dzVents: Info: Device Smoke Alarm (320) state: Off; last Updated: 2020-05-25 19:20:50
2020-06-02 16:36:15.568 Status: dzVents: Info: Device Heat (321) state: Off; last Updated: 2020-06-02 13:54:20
2020-06-02 16:36:15.568 Status: dzVents: Info: Device Home Security (322) state: On; last Updated: 2020-06-02 13:54:19
2020-06-02 16:36:15.569 Status: dzVents: Info: Device Power Management (323) state: Off; last Updated: 2020-06-02 13:45:00
2020-06-02 16:36:15.569 Status: dzVents: Info: Device System (324) state: Off; last Updated: 2020-06-02 13:45:00
2020-06-02 16:36:15.569 Status: dzVents: Info: Device General (325) state: On; last Updated: 2020-06-02 13:54:20
2020-06-02 16:36:15.569 Status: dzVents: Info: Device Alarm Type: Smoke Alarm 1 (0x01) (326) state: Clear; last Updated: 2020-06-02 16:35:54
2020-06-02 16:36:15.569 Status: dzVents: Info: Device Alarm Type: Home Security 7 (0x07) (327) state: Tampering - Cover Removed; last Updated: 2020-06-02 13:54:19
2020-06-02 16:36:15.569 Status: dzVents: Info: ------ Finished DZ_Test
2020-06-02 16:36:15.775 Status: dzVents: Info: ------ Start internal script: DZ_Test: Device: "Temp Overloop (Z-wave)", Index: 185
2020-06-02 16:36:15.775 Status: dzVents: Info: Device Temp Overloop (185) triggered this script
2020-06-02 16:36:15.775 Status: dzVents: Info: Device Temp Overloop (185) state: 26.4; last Updated: 2020-06-02 16:22:23
2020-06-02 16:36:15.776 Status: dzVents: Info: Device Sensor (319) state: Off; last Updated: 2020-05-24 16:31:46
2020-06-02 16:36:15.777 Status: dzVents: Info: Device Smoke Alarm (320) state: Off; last Updated: 2020-05-25 19:20:50
2020-06-02 16:36:15.777 Status: dzVents: Info: Device Smoke Alarm (320) state: Off; last Updated: 2020-05-25 19:20:50
2020-06-02 16:36:15.778 Status: dzVents: Info: Device Heat (321) state: Off; last Updated: 2020-06-02 13:54:20
2020-06-02 16:36:15.779 Status: dzVents: Info: Device Home Security (322) state: On; last Updated: 2020-06-02 13:54:19
2020-06-02 16:36:15.780 Status: dzVents: Info: Device Power Management (323) state: Off; last Updated: 2020-06-02 13:45:00
2020-06-02 16:36:15.781 Status: dzVents: Info: Device System (324) state: Off; last Updated: 2020-06-02 13:45:00
2020-06-02 16:36:15.781 Status: dzVents: Info: Device General (325) state: On; last Updated: 2020-06-02 13:54:20
2020-06-02 16:36:15.782 Status: dzVents: Info: Device Alarm Type: Smoke Alarm 1 (0x01) (326) state: Clear; last Updated: 2020-06-02 16:36:15
2020-06-02 16:36:15.783 Status: dzVents: Info: Device Alarm Type: Home Security 7 (0x07) (327) state: Tampering - Cover Removed; last Updated: 2020-06-02 13:54:19
2020-06-02 16:36:15.783 Status: dzVents: Info: ------ Finished DZ_Test
2020-06-02 16:36:17.693 (Z-wave) General/kWh (kWh Droger)
2020-06-02 16:36:17.713 (Power-Gas) P1 Smart Meter (kWh Totaal)
2020-06-02 16:36:24.079 (Z-wave) Temp (Temp Overloop)
2020-06-02 16:36:24.217 Status: dzVents: Info: ------ Start internal script: DZ_Test: Device: "Temp Overloop (Z-wave)", Index: 185
2020-06-02 16:36:24.217 Status: dzVents: Info: Device Temp Overloop (185) triggered this script
2020-06-02 16:36:24.217 Status: dzVents: Info: Device Temp Overloop (185) state: 26.5; last Updated: 2020-06-02 16:36:15
2020-06-02 16:36:24.218 Status: dzVents: Info: Device Sensor (319) state: Off; last Updated: 2020-05-24 16:31:46
2020-06-02 16:36:24.219 Status: dzVents: Info: Device Smoke Alarm (320) state: Off; last Updated: 2020-05-25 19:20:50
2020-06-02 16:36:24.219 Status: dzVents: Info: Device Smoke Alarm (320) state: Off; last Updated: 2020-05-25 19:20:50
2020-06-02 16:36:24.220 Status: dzVents: Info: Device Heat (321) state: Off; last Updated: 2020-06-02 13:54:20
2020-06-02 16:36:24.221 Status: dzVents: Info: Device Home Security (322) state: On; last Updated: 2020-06-02 13:54:19
2020-06-02 16:36:24.222 Status: dzVents: Info: Device Power Management (323) state: Off; last Updated: 2020-06-02 13:45:00
2020-06-02 16:36:24.223 Status: dzVents: Info: Device System (324) state: Off; last Updated: 2020-06-02 13:45:00
2020-06-02 16:36:24.223 Status: dzVents: Info: Device General (325) state: On; last Updated: 2020-06-02 13:54:20
2020-06-02 16:36:24.224 Status: dzVents: Info: Device Alarm Type: Smoke Alarm 1 (0x01) (326) state: Clear; last Updated: 2020-06-02 16:36:15
2020-06-02 16:36:24.225 Status: dzVents: Info: Device Alarm Type: Home Security 7 (0x07) (327) state: Tampering - Cover Removed; last Updated: 2020-06-02 13:54:19
2020-06-02 16:36:24.225 Status: dzVents: Info: ------ Finished DZ_Test 
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: create DzVents script based on Smoke Alarm Fibaro Smoke 2

Post by waaren »

Ragdag wrote: Tuesday 02 June 2020 16:36 That does give us some insight :)

Code: Select all

2020-06-02 16:35:54.284 Status: dzVents: Info: Device Alarm Type: Smoke Alarm 1 (0x01) (326) triggered this script
2020-06-02 16:35:54.292 Status: dzVents: Info: Device Alarm Type: Smoke Alarm 1 (0x01) (326) state: Smoke Test; last Updated: 2020-06-02 13:56:44
With this you should have enough information to build a dzVents script with actions based on the various states of device 326
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
Ragdag
Posts: 147
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: create DzVents script based on Smoke Alarm Fibaro Smoke 2

Post by Ragdag »

I'm a bit stuck.

Yours obviously worked

Code: Select all

local myAlarm = { 319,320,320,321,322,323,324,325,326,327}
return 
{
    on = 
    {
        devices = myAlarm,
    },

    logging =
    {
        level = domoticz.LOG_INFO,
    },

    execute = function(dz, item)
        dz.log('Device ' .. item.name .. ' (' .. item.idx .. ') triggered this script', dz.LOG_INFO)
        
        for _, idx in ipairs(myAlarm) do
            local device = dz.devices(idx)
            if dz.utils.deviceExists(idx) then
                dz.log('Device ' .. device.name .. ' (' .. device.idx .. ') state: ' .. device.state .. '; last Updated: ' .. device.lastUpdate.rawDateTime, dz.LOG_INFO)
            end
        end
    end
}
This is the log entry from you script

Code: Select all

2020-06-03 12:33:36.765 (Z-wave) General/Alarm (Alarm Type: Smoke Alarm 1 (0x01))
2020-06-03 12:33:36.783 (Z-wave) Light/Switch (Smoke Alarm)
2020-06-03 12:33:36.742 Status: OpenZWave: Alarm received (Smoke Alarm: Smoke Test), NodeID: 12 (0x0c)
2020-06-03 12:33:36.906 Status: dzVents: Info: ------ Start internal script: DZ_Test: Device: "Alarm Type: Smoke Alarm 1 (0x01) (Z-wave)", Index: 326
2020-06-03 12:33:36.906 Status: dzVents: Info: Device Alarm Type: Smoke Alarm 1 (0x01) (326) triggered this script
2020-06-03 12:33:36.907 Status: dzVents: Info: Device Alarm Type: Smoke Alarm 1 (0x01) (326) state: Smoke Test; last Updated: 2020-06-03 12:29:09
2020-06-03 12:33:36.908 Status: dzVents: Info: ------ Finished DZ_Test 
When I try to incorporate that in my script it is not even triggered.

Code: Select all

local scriptVar = 'FIREALARM'
local myAlarm = { 326,329,336}
return 
{
	on = 
	{
		devices = 
		{
            myAlarm,
        }
	},
    
    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

	execute = function(dz, item)
	    
        if item.isHTTPResponse then
            dz.log(item.data,dz.LOG_DEBUG)
            return
        end
        
        local function pushover(PushoverUser, PushoverApp, title, message, priority, sound)
            dz.openURL({
                url = 'https://api.pushover.net/1/messages.json',
                method = 'POST',
                callback = scriptVar,
                postData = 
                {
                    token = PushoverApp.token,
                    user =  PushoverUser.key,
                    message = message,
                    title = title or 'Pushover from dzVents',
                    priority = priority or 0,
                    sound = sound or 'echo',
                },
            })
        end

        local PushoverUsers = 
        {
            ['USER1'] = { ['key'] = 'aaa' },
            ['USER2'] = { ['key'] = 'bbb'},
            ['Familie'] = { ['key'] = 'ccc'},
        }

        local PushoverApps = 
        {
            ['Domoticz'] = { ['token'] = 'ddd' },
            ['Huis'] = { ['token'] = 'eee' },
            ['Test'] = { ['token'] = 'fff' },
            ['Was'] = { ['token'] = 'ggg' },
            ['Alarm'] = { ['token'] = 'hhh' },
        }

        dz.log('Device ' .. item.name .. ' (' .. item.idx .. ') triggered this script', dz.LOG_DEBUG)
        for _, idx in ipairs(myAlarm) do
			local device = dz.devices(idx)
			if dz.utils.deviceExists(idx) then
				dz.log('Device ' .. device.name .. ' (' .. device.idx .. ') state: ' .. device.state .. '; last Updated: ' .. device.lastUpdate.rawDateTime, dz.LOG_DEBUG)
				pushover(PushoverUsers.USER1, PushoverApps.Alarm, 'Brand Alarm', 'Device ' .. device.name .. ' state: ' .. device.state, 1, 'siren' )
			end
		end
    end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: create DzVents script based on Smoke Alarm Fibaro Smoke 2

Post by waaren »

Ragdag wrote: Wednesday 03 June 2020 12:41 I'm a bit stuck.
When I try to incorporate that in my script it is not even triggered.
myAlarm is already a table so the extra pair of {} do not work

try:

Code: Select all

	on = 
	{
		devices = myAlarm,
	},
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
Ragdag
Posts: 147
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: create DzVents script based on Smoke Alarm Fibaro Smoke 2

Post by Ragdag »

waaren wrote: Wednesday 03 June 2020 15:58
Ragdag wrote: Wednesday 03 June 2020 12:41 I'm a bit stuck.
When I try to incorporate that in my script it is not even triggered.
myAlarm is already a table so the extra pair of {} do not work

try:

Code: Select all

	on = 
	{
		devices = myAlarm,
	},
This is already much better :)

I'm getting messages through PushOver but it seems that it is repeating the alerts each time the alarm sounds during a test
Image

Need to figure out how to weed those out.

PS: Is there a way for the log in Domoticz not to roll over so fast?
My log rolls over in about 20 minutes
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: create DzVents script based on Smoke Alarm Fibaro Smoke 2

Post by waaren »

Ragdag wrote: Thursday 04 June 2020 13:11 This is already much better :)

I'm getting messages through PushOver but it seems that it is repeating the alerts each time the alarm sounds during a test
Need to figure out how to weed those out.
can you try changing

Code: Select all

pushover(PushoverUsers.USER1, PushoverApps.Alarm, 'Brand Alarm', 'Device ' .. device.name .. ' state: ' .. device.state, 1, 'siren' )
to

Code: Select all

if device.lastUpdate.secondsAgo > 60 then
	pushover(PushoverUsers.USER1, PushoverApps.Alarm, 'Brand Alarm', 'Device ' .. device.name .. ' state: ' .. device.state, 1, 'siren' )
end
PS: Is there a way for the log in Domoticz not to roll over so fast?
My log rolls over in about 20 minutes
I log to an os.file() ( You can do that by modifying /etc/init.d/domoticz.sh and restart domoticz )
and after archiving it once a day, I start with an empty one. (using sudo truncate -s 0 /var/log/domoticz.log)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
Ragdag
Posts: 147
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: create DzVents script based on Smoke Alarm Fibaro Smoke 2

Post by Ragdag »

waaren wrote: Thursday 04 June 2020 13:35
Ragdag wrote: Thursday 04 June 2020 13:11 This is already much better :)

I'm getting messages through PushOver but it seems that it is repeating the alerts each time the alarm sounds during a test
Need to figure out how to weed those out.
can you try changing

Code: Select all

pushover(PushoverUsers.USER1, PushoverApps.Alarm, 'Brand Alarm', 'Device ' .. device.name .. ' state: ' .. device.state, 1, 'siren' )
to

Code: Select all

if device.lastUpdate.secondsAgo > 60 then
	pushover(PushoverUsers.USER1, PushoverApps.Alarm, 'Brand Alarm', 'Device ' .. device.name .. ' state: ' .. device.state, 1, 'siren' )
end
PS: Is there a way for the log in Domoticz not to roll over so fast?
My log rolls over in about 20 minutes
I log to an os.file() ( You can do that by modifying /etc/init.d/domoticz.sh and restart domoticz )
and after archiving it once a day, I start with an empty one. (using sudo truncate -s 0 /var/log/domoticz.log)
There also seems to be a switch associated with the Smoke Alarm
Image

If I view the logging there it seems to only fire once when the alarm is triggered and switching off when it is done.
Image
So I think I use that one as a hidden Switch to trigger the PushOver alert and then read the Alarm State for the message.
Weird thing here is that it somehow attaches the switch action to the user of my wife :?: while it is only triggered directly through the Smoke Sensor

On the logging, won't logging to SD Card wear out my SD card really fast?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: create DzVents script based on Smoke Alarm Fibaro Smoke 2

Post by waaren »

Ragdag wrote: Thursday 04 June 2020 13:44 On the logging, won't logging to SD Card wear out my SD card really fast?
Faster then without but I never had any corrupt SD card during the years I still used SD cards for this. If you do a quick search in this forum you will find that there are many opinions on the topic and also a lot of creative alternatives.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
Ragdag
Posts: 147
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: create DzVents script based on Smoke Alarm Fibaro Smoke 2

Post by Ragdag »

waaren wrote: Thursday 04 June 2020 13:54
Ragdag wrote: Thursday 04 June 2020 13:44 On the logging, won't logging to SD Card wear out my SD card really fast?
Faster then without but I never had any corrupt SD card during the years I still used SD cards for this. If you do a quick search in this forum you will find that there are many opinions on the topic and also a lot of creative alternatives.
Thanks, will take a stab at that.

Just tested with my revised script but it also looks trips multiple times using the switch.
It does not make sense for me since I do not see the switch being sent multiple times in the log

It triggers at 14:13:15.652 and that triggers 3 devices.
Then at 14:13:27.723 it finished the test and holds the alarm and switches off the 3 devices

Code: Select all

2020-06-04 14:13:15.652 (Z-wave) Light/Switch (Sensor)
2020-06-04 14:13:15.665 (Z-wave) General/Alarm (Alarm Type: Smoke Alarm 1 (0x01))
2020-06-04 14:13:15.682 (Z-wave) Light/Switch (Smoke Alarm - Overloop)
2020-06-04 14:13:15.649 Status: OpenZWave: Alarm received (Smoke Alarm: Smoke Test), NodeID: 12 (0x0c)
2020-06-04 14:13:15.896 Status: dzVents: Info: FireAlarm: ------ Start internal script: DZ_FireAlarm_v2: Device: "Smoke Alarm - Overloop (Z-wave)", Index: 320
2020-06-04 14:13:15.897 Status: dzVents: Debug: FireAlarm: Processing device-adapter for $Smoke Alarm - Schuur: Switch device adapter
2020-06-04 14:13:15.898 Status: dzVents: Debug: FireAlarm: Processing device-adapter for $Smoke Alarm - Zolder: Switch device adapter
2020-06-04 14:13:15.901 Status: dzVents: Debug: FireAlarm: OpenURL: url = https://api.pushover.net/1/messages.json
2020-06-04 14:13:15.901 Status: dzVents: Debug: FireAlarm: OpenURL: method = POST
2020-06-04 14:13:15.901 Status: dzVents: Debug: FireAlarm: OpenURL: post data = {"message":"Brand Alarm Schuur\nStatus: Clear","priority":1,"sound":"siren","title":"Brand Alarm","token":"bbb","user":"aaa"}
2020-06-04 14:13:15.901 Status: dzVents: Debug: FireAlarm: OpenURL: headers = {["Content-Type"]="application/json"}
2020-06-04 14:13:15.901 Status: dzVents: Debug: FireAlarm: OpenURL: callback = FireAlarm
2020-06-04 14:13:15.901 Status: dzVents: Debug: FireAlarm: OpenURL: url = https://api.pushover.net/1/messages.json
2020-06-04 14:13:15.901 Status: dzVents: Debug: FireAlarm: OpenURL: method = POST
2020-06-04 14:13:15.901 Status: dzVents: Debug: FireAlarm: OpenURL: post data = {"message":"Brand Alarm Schuur\nStatus: Smoke Test","priority":1,"sound":"siren","title":"Brand Alarm","token":"bbb","user":"aaa"}
2020-06-04 14:13:15.901 Status: dzVents: Debug: FireAlarm: OpenURL: headers = {["Content-Type"]="application/json"}
2020-06-04 14:13:15.901 Status: dzVents: Debug: FireAlarm: OpenURL: callback = FireAlarm
2020-06-04 14:13:15.901 Status: dzVents: Debug: FireAlarm: OpenURL: url = https://api.pushover.net/1/messages.json
2020-06-04 14:13:15.901 Status: dzVents: Debug: FireAlarm: OpenURL: method = POST
2020-06-04 14:13:15.901 Status: dzVents: Debug: FireAlarm: OpenURL: post data = {"message":"Brand Alarm Schuur\nStatus: Clear","priority":1,"sound":"siren","title":"Brand Alarm","token":"bbb","user":"aaa"}
2020-06-04 14:13:15.901 Status: dzVents: Debug: FireAlarm: OpenURL: headers = {["Content-Type"]="application/json"}
2020-06-04 14:13:15.902 Status: dzVents: Debug: FireAlarm: OpenURL: callback = FireAlarm
2020-06-04 14:13:15.902 Status: dzVents: Info: FireAlarm: ------ Finished DZ_FireAlarm_v2
2020-06-04 14:13:19.512 (Power-Gas) P1 Smart Meter (kWh Totaal)
2020-06-04 14:13:26.175 (Z-wave) Temp (Temp Overloop)
2020-06-04 14:13:27.013 (Z-wave) Usage (Unknown)
2020-06-04 14:13:27.023 (Z-wave) General/kWh (kWh Wasmachine)
2020-06-04 14:13:27.723 (Z-wave) Light/Switch (Sensor)
2020-06-04 14:13:27.729 (Z-wave) General/Alarm (Alarm Type: Smoke Alarm 1 (0x01))
2020-06-04 14:13:27.737 (Z-wave) Light/Switch (Smoke Alarm - Overloop)
2020-06-04 14:13:27.720 Status: OpenZWave: Alarm received (Smoke Alarm: Clear), NodeID: 12 (0x0c)
2020-06-04 14:13:27.975 Status: dzVents: Info: FireAlarm: ------ Start internal script: DZ_FireAlarm_v2: Device: "Smoke Alarm - Overloop (Z-wave)", Index: 320
2020-06-04 14:13:27.976 Status: dzVents: Debug: FireAlarm: Processing device-adapter for $Smoke Alarm - Schuur: Switch device adapter
2020-06-04 14:13:27.976 Status: dzVents: Debug: FireAlarm: Processing device-adapter for $Smoke Alarm - Zolder: Switch device adapter
2020-06-04 14:13:27.979 Status: dzVents: Debug: FireAlarm: OpenURL: url = https://api.pushover.net/1/messages.json
2020-06-04 14:13:27.979 Status: dzVents: Debug: FireAlarm: OpenURL: method = POST
2020-06-04 14:13:27.979 Status: dzVents: Debug: FireAlarm: OpenURL: post data = {"message":"Brand Alarm Schuur\nStatus: Clear","priority":1,"sound":"siren","title":"Brand Alarm","token":"bbb","user":"aaa"}
2020-06-04 14:13:27.979 Status: dzVents: Debug: FireAlarm: OpenURL: headers = {["Content-Type"]="application/json"}
2020-06-04 14:13:27.979 Status: dzVents: Debug: FireAlarm: OpenURL: callback = FireAlarm
2020-06-04 14:13:27.980 Status: dzVents: Debug: FireAlarm: OpenURL: url = https://api.pushover.net/1/messages.json
2020-06-04 14:13:27.980 Status: dzVents: Debug: FireAlarm: OpenURL: method = POST
2020-06-04 14:13:27.980 Status: dzVents: Debug: FireAlarm: OpenURL: post data = {"message":"Brand Alarm Schuur\nStatus: Clear","priority":1,"sound":"siren","title":"Brand Alarm","token":"bbb","user":"aaa"}
2020-06-04 14:13:27.980 Status: dzVents: Debug: FireAlarm: OpenURL: headers = {["Content-Type"]="application/json"}
2020-06-04 14:13:27.980 Status: dzVents: Debug: FireAlarm: OpenURL: callback = FireAlarm
2020-06-04 14:13:27.980 Status: dzVents: Debug: FireAlarm: OpenURL: url = https://api.pushover.net/1/messages.json
2020-06-04 14:13:27.980 Status: dzVents: Debug: FireAlarm: OpenURL: method = POST
2020-06-04 14:13:27.980 Status: dzVents: Debug: FireAlarm: OpenURL: post data = {"message":"Brand Alarm Schuur\nStatus: Clear","priority":1,"sound":"siren","title":"Brand Alarm","token":"bbb","user":"aaa"}
2020-06-04 14:13:27.980 Status: dzVents: Debug: FireAlarm: OpenURL: headers = {["Content-Type"]="application/json"}
2020-06-04 14:13:27.980 Status: dzVents: Debug: FireAlarm: OpenURL: callback = FireAlarm
2020-06-04 14:13:27.980 Status: dzVents: Info: FireAlarm: ------ Finished DZ_FireAlarm_v2
Somehow in the DzVents script is triggered 6 times while the switch that triggers the DzVents is only switched 2 times
Image

Here is my current script

Code: Select all

local scriptVar = 'FireAlarm'

return 
{
    on = 
    {
        devices = 
        {
            303, -- Schuur
            320, -- Overloop
            330, -- Zolder
        }
    },
    
    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    execute = function(dz, item)
        
        if item.isHTTPResponse then
            dz.log(item.data,dz.LOG_DEBUG)
            return
        end
        
        local function pushover(PushoverUser, PushoverApp, title, message, priority, sound)
            dz.openURL({
                url = 'https://api.pushover.net/1/messages.json',
                method = 'POST',
                callback = scriptVar,
                postData = 
                {
                    token = PushoverApp.token,
                    user =  PushoverUser.key,
                    message = message,
                    title = title or 'Pushover from dzVents',
                    priority = priority or 0,
                    sound = sound or 'echo',
                },
            })
        end

        local PushoverUsers = 
        {
            ['USER1'] = { ['key'] = 'aaa' },
            ['USER2'] = { ['key'] = 'bbb'},
            ['Familie'] = { ['key'] = 'ccc'},
        }

        local PushoverApps = 
        {
            ['Domoticz'] = { ['token'] = 'ddd' },
            ['Huis'] = { ['token'] = 'eee' },
            ['Test'] = { ['token'] = 'fff' },
            ['Was'] = { ['token'] = 'ggg' },
            ['Alarm'] = { ['token'] = 'hhh' },
        }
        
        
        local SchuurSmokeSwitch = dz.devices(303)
        local OverloopSmokeSwitch = dz.devices(320)
        local ZolderSmokeSwitch = dz.devices(330)

        local SchuurSmokeAlarm = dz.devices(336)
        local OverloopSmokeAlarm = dz.devices(326)
        local ZolderSmokeAlarm = dz.devices(329)

        
        if (item.isDevice) then 
            if (SchuurSmokeSwitch.state == 'On') then
                pushover(PushoverUsers.USER1, PushoverApps.Alarm, 'Brand Alarm', 'Brand Alarm Schuur\nStatus: ' .. SchuurSmokeAlarm.state, 1, 'siren' )
            elseif (SchuurSmokeSwitch.state == 'Off') then
                pushover(PushoverUsers.USER1, PushoverApps.Alarm, 'Brand Alarm', 'Brand Alarm Schuur\nStatus: ' .. SchuurSmokeAlarm.state, 1, 'siren' )
            end

            if (OverloopSmokeSwitch.state == 'On') then
                pushover(PushoverUsers.USER1, PushoverApps.Alarm, 'Brand Alarm', 'Brand Alarm Overloop\nStatus: ' .. OverloopSmokeAlarm.state, 1, 'siren' )
            elseif (OverloopSmokeSwitch.state == 'Off') then
                pushover(PushoverUsers.USER1, PushoverApps.Alarm, 'Brand Alarm', 'Brand Alarm Overloop\nStatus: ' .. OverloopSmokeAlarm.state, 1, 'siren' )
            end

            if (ZolderSmokeSwitch.state == 'On') then
                pushover(PushoverUsers.USER1, PushoverApps.Alarm, 'Brand Alarm', 'Brand Alarm Zolder\nStatus: ' .. ZolderSmokeAlarm.state, 1, 'siren' )
            elseif (ZolderSmokeSwitch.state == 'Off') then
                pushover(PushoverUsers.USER1, PushoverApps.Alarm, 'Brand Alarm', 'Brand Alarm Zolder\nStatus: ' .. ZolderSmokeAlarm.state, 1, 'siren' )
            end

        end
    end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: create DzVents script based on Smoke Alarm Fibaro Smoke 2

Post by waaren »

Ragdag wrote: Thursday 04 June 2020 14:28 Somehow in the DzVents script is triggered 6 times while the switch that triggers the DzVents is only switched 2 times
Image
The log is lying :D

See this issue (Also applicable for standard switches)

I still think that the

Code: Select all

if device.lastUpdate.secondsAgo > 60 
approach should provide you with a workable solution
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
Ragdag
Posts: 147
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: create DzVents script based on Smoke Alarm Fibaro Smoke 2

Post by Ragdag »

waaren wrote: Thursday 04 June 2020 14:35
Ragdag wrote: Thursday 04 June 2020 14:28 Somehow in the DzVents script is triggered 6 times while the switch that triggers the DzVents is only switched 2 times
Image
The log is lying :D

See this issue (Also applicable for standard switches)

I still think that the

Code: Select all

if device.lastUpdate.secondsAgo > 60 
approach should provide you with a workable solution
But wouldn't the log still have z-wave commands for the switches being triggered as all z-wave commands are logged, can understand in the Switch GUI log that it is truncated.
I'll give that a try with the last updatetime :)
User avatar
Ragdag
Posts: 147
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: create DzVents script based on Smoke Alarm Fibaro Smoke 2

Post by Ragdag »

Hold on I now see the problem :D

The logic I have is this

Code: Select all

        if (item.isDevice) then 
            if (SchuurSmokeSwitch.state == 'On') then
                pushover(PushoverUsers.User1, PushoverApps.Alarm, 'Brand Alarm', 'Brand Alarm Schuur\nStatus: ' .. SchuurSmokeAlarm.state, 1, 'siren' )
            elseif (SchuurSmokeSwitch.state == 'Off') then
                pushover(PushoverUsers.User1, PushoverApps.Alarm, 'Brand Alarm', 'Brand Alarm Schuur\nStatus: ' .. SchuurSmokeAlarm.state, 1, 'siren' )
            end

            if (OverloopSmokeSwitch.state == 'On') then
                pushover(PushoverUsers.User1, PushoverApps.Alarm, 'Brand Alarm', 'Brand Alarm Overloop\nStatus: ' .. OverloopSmokeAlarm.state, 1, 'siren' )
            elseif (OverloopSmokeSwitch.state == 'Off') then
                pushover(PushoverUsers.User1, PushoverApps.Alarm, 'Brand Alarm', 'Brand Alarm Overloop\nStatus: ' .. OverloopSmokeAlarm.state, 1, 'siren' )
            end

            if (ZolderSmokeSwitch.state == 'On') then
                pushover(PushoverUsers.User1, PushoverApps.Alarm, 'Brand Alarm', 'Brand Alarm Zolder\nStatus: ' .. ZolderSmokeAlarm.state, 1, 'siren' )
            elseif (ZolderSmokeSwitch.state == 'Off') then
                pushover(PushoverUsers.User1, PushoverApps.Alarm, 'Brand Alarm', 'Brand Alarm Zolder\nStatus: ' .. ZolderSmokeAlarm.state, 1, 'siren' )
            end

        end
When 1 switch is triggered it will evaluate all if statements and fire off the respective messages resulting in 6 messages.
Image

Is there a way to only evaluated the if statement for the device that triggers the script?

Would it help if I moved the (item.isDevice) into the separate if statments?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: create DzVents script based on Smoke Alarm Fibaro Smoke 2

Post by waaren »

Ragdag wrote: Thursday 04 June 2020 14:57 Hold on I now see the problem :D
Would it help if I moved the (item.isDevice) into the separate if statments?
Can you try this ?

Code: Select all

local scriptVar = 'FireAlarm'

return
{
    on =
    {
        devices =
        {
            303, -- Schuur
            320, -- Overloop
            330, -- Zolder
        }
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    execute = function(dz, item)

        if item.isHTTPResponse then
            dz.log(item.data,dz.LOG_DEBUG)
            return
        end

        local function pushover(PushoverUser, PushoverApp, title, message, priority, sound)
            dz.openURL({
                url = 'https://api.pushover.net/1/messages.json',
                method = 'POST',
                callback = scriptVar,
                postData =
                {
                    token = PushoverApp.token,
                    user =  PushoverUser.key,
                    message = message,
                    title = title or 'Pushover from dzVents',
                    priority = priority or 0,
                    sound = sound or 'echo',
                },
            })
        end

        local PushoverUsers =
        {
            ['USER1'] = { ['key'] = 'aaa' },
            ['USER2'] = { ['key'] = 'bbb'},
            ['Familie'] = { ['key'] = 'ccc'},
        }

        local PushoverApps =
        {
            ['Domoticz'] = { ['token'] = 'ddd' },
            ['Huis'] = { ['token'] = 'eee' },
            ['Test'] = { ['token'] = 'fff' },
            ['Was'] = { ['token'] = 'ggg' },
            ['Alarm'] = { ['token'] = 'hhh' },
        }

        if item == dz.devices(303) then
            item.alarmDevice = 336
            item.alarmText = 'Schuur'
        elseif item == dz.devices(320) then
            item.alarmDevice = 326
            item.alarmText = 'Overloop'
        elseif item == dz.devices(330) then
            item.alarmDevice = 329
            item.alarmText = 'Zolder'
        else
            dz.log('Unknown device', dz.LOG_ERROR)
            return
        end


        if ( item.state == 'On' and item.lastUpdate.secondsAgo > 60 ) or item.state == 'Off'  then
            pushover(PushoverUsers.USER1, PushoverApps.Alarm, 'Brand Alarm', 'Brand Alarm ' .. item.alarmText .. '\nStatus: ' .. dz.devices(item.alarmDevice).state, 1, 'siren' )
        end

    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
Ragdag
Posts: 147
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: create DzVents script based on Smoke Alarm Fibaro Smoke 2  [Solved]

Post by Ragdag »

Figured it out with the help of this thread https://www.domoticz.com/forum/viewtopi ... pt#p248557

This is now the complete script

Code: Select all

local scriptVar = 'FireAlarm'

return 
{
    on = 
    {
        devices = 
        {
            303, -- Schuur
            320, -- Overloop
            330, -- Zolder
        }
    },
    
    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    execute = function(dz, item)
        
        if item.isHTTPResponse then
            dz.log(item.data,dz.LOG_DEBUG)
            return
        end
        
        local function pushover(PushoverUser, PushoverApp, title, message, priority, sound)
            dz.openURL({
                url = 'https://api.pushover.net/1/messages.json',
                method = 'POST',
                callback = scriptVar,
                postData = 
                {
                    token = PushoverApp.token,
                    user =  PushoverUser.key,
                    message = message,
                    title = title or 'Pushover from dzVents',
                    priority = priority or 0,
                    sound = sound or 'echo',
                },
            })
        end

        local PushoverUsers = 
        {
            ['USER1'] = { ['key'] = 'aaa' },
            ['USER2'] = { ['key'] = 'bbb'},
            ['Familie'] = { ['key'] = 'ccc'},
        }

        local PushoverApps = 
        {
            ['Domoticz'] = { ['token'] = 'ddd' },
            ['Huis'] = { ['token'] = 'eee' },
            ['Test'] = { ['token'] = 'fff' },
            ['Was'] = { ['token'] = 'ggg' },
            ['Alarm'] = { ['token'] = 'hhh' },
        }
        
        
        local SchuurSmokeSwitch = dz.devices(303)
        local OverloopSmokeSwitch = dz.devices(320)
        local ZolderSmokeSwitch = dz.devices(330)

        local SchuurSmokeAlarm = dz.devices(336)
        local OverloopSmokeAlarm = dz.devices(326)
        local ZolderSmokeAlarm = dz.devices(329)

        
        if (item.isDevice) then 
            if (item == SchuurSmokeSwitch) then
                if (SchuurSmokeSwitch.state == 'On') then
                    pushover(PushoverUsers.USER1, PushoverApps.Alarm, 'Brand Alarm', 'Brand Alarm Schuur\nStatus: ' .. SchuurSmokeAlarm.state, 1, 'siren' )
                elseif (SchuurSmokeSwitch.state == 'Off') then
                    pushover(PushoverUsers.USER1, PushoverApps.Alarm, 'Brand Alarm', 'Brand Alarm Schuur\nStatus: ' .. SchuurSmokeAlarm.state, 1, 'siren' )
                end
            end

            if (item == OverloopSmokeSwitch) then
                if (OverloopSmokeSwitch.state == 'On') then
                    pushover(PushoverUsers.USER1, PushoverApps.Alarm, 'Brand Alarm', 'Brand Alarm Overloop\nStatus: ' .. OverloopSmokeAlarm.state, 1, 'siren' )
                elseif (OverloopSmokeSwitch.state == 'Off') then
                    pushover(PushoverUsers.USER1, PushoverApps.Alarm, 'Brand Alarm', 'Brand Alarm Overloop\nStatus: ' .. OverloopSmokeAlarm.state, 1, 'siren' )
                end
            end
        
            if (item == ZolderSmokeSwitch) then
                if (ZolderSmokeSwitch.state == 'On') then
                    pushover(PushoverUsers.USER1, PushoverApps.Alarm, 'Brand Alarm', 'Brand Alarm Zolder\nStatus: ' .. ZolderSmokeAlarm.state, 1, 'siren' )
                elseif (ZolderSmokeSwitch.state == 'Off') then
                    pushover(PushoverUsers.USER1, PushoverApps.Alarm, 'Brand Alarm', 'Brand Alarm Zolder\nStatus: ' .. ZolderSmokeAlarm.state, 1, 'siren' )
                end
            end
        end
    end
}

With this beautiful result
Image

waaren, again thank you for you help and support!

EDIT:
I now see that you suggested a similar approach but yours seems to be more intelligent :)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: create DzVents script based on Smoke Alarm Fibaro Smoke 2

Post by waaren »

Ragdag wrote: Thursday 04 June 2020 15:27 I now see that you suggested a similar approach.
I updated my last post just yet. Can you please test the latest version?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
Ragdag
Posts: 147
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: create DzVents script based on Smoke Alarm Fibaro Smoke 2

Post by Ragdag »

waaren wrote: Thursday 04 June 2020 15:36
Ragdag wrote: Thursday 04 June 2020 15:27 I now see that you suggested a similar approach.
I updated my last post just yet. Can you please test the latest version?
Yours also works but the lastupdate can be removed as that is no longer needed since that switch is only triggered once.

Since your script is more elegant than mine I will use that one :)
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 0 guests