diff --git a/front/src/config/i18n/en.json b/front/src/config/i18n/en.json
index 0d3d91c4d5..1a1115b968 100644
--- a/front/src/config/i18n/en.json
+++ b/front/src/config/i18n/en.json
@@ -1572,6 +1572,9 @@
},
"calendar": {
"event-is-coming": "Calendar event is coming"
+ },
+ "system": {
+ "start": "Gladys starting"
}
},
"triggersCard": {
@@ -1656,6 +1659,9 @@
"minute": "minutes",
"hour": "hours",
"day": "days"
+ },
+ "gladysStart": {
+ "description": "This scene will be executed each time Gladys starts"
}
}
},
diff --git a/front/src/config/i18n/fr.json b/front/src/config/i18n/fr.json
index 3aa1e4f29d..e2a5b3316c 100644
--- a/front/src/config/i18n/fr.json
+++ b/front/src/config/i18n/fr.json
@@ -1574,6 +1574,9 @@
},
"calendar": {
"event-is-coming": "Un évènement dans le calendrier arrive"
+ },
+ "system": {
+ "start": "Gladys démarre"
}
},
"triggersCard": {
@@ -1658,6 +1661,9 @@
"minute": "minutes",
"hour": "heures",
"day": "jours"
+ },
+ "gladysStart": {
+ "description": "Cette scène sera exécutée à chaque démarrage de Gladys"
}
}
},
diff --git a/front/src/routes/scene/edit-scene/TriggerCard.jsx b/front/src/routes/scene/edit-scene/TriggerCard.jsx
index 32d3384543..3c43c1eba1 100644
--- a/front/src/routes/scene/edit-scene/TriggerCard.jsx
+++ b/front/src/routes/scene/edit-scene/TriggerCard.jsx
@@ -12,6 +12,7 @@ import UserEnteredOrLeftArea from './triggers/UserEnteredOrLeftArea';
import CalendarEventIsComing from './triggers/CalendarEventIsComing';
import { EVENTS } from '../../../../../server/utils/constants';
+import GladysStartTrigger from './triggers/GladysStartTrigger';
const deleteTriggerFromList = (deleteTrigger, index) => () => {
deleteTrigger(index);
@@ -20,6 +21,7 @@ const deleteTriggerFromList = (deleteTrigger, index) => () => {
const TriggerCard = ({ children, ...props }) => (
);
diff --git a/front/src/routes/scene/edit-scene/triggers/ChooseTriggerTypeCard.jsx b/front/src/routes/scene/edit-scene/triggers/ChooseTriggerTypeCard.jsx
index 07684edae5..4ef4bf8b2c 100644
--- a/front/src/routes/scene/edit-scene/triggers/ChooseTriggerTypeCard.jsx
+++ b/front/src/routes/scene/edit-scene/triggers/ChooseTriggerTypeCard.jsx
@@ -18,7 +18,8 @@ const TRIGGER_LIST = [
EVENTS.HOUSE.NO_LONGER_EMPTY,
EVENTS.AREA.USER_ENTERED,
EVENTS.AREA.USER_LEFT,
- EVENTS.CALENDAR.EVENT_IS_COMING
+ EVENTS.CALENDAR.EVENT_IS_COMING,
+ EVENTS.SYSTEM.START
];
class ChooseTriggerType extends Component {
diff --git a/front/src/routes/scene/edit-scene/triggers/GladysStartTrigger.jsx b/front/src/routes/scene/edit-scene/triggers/GladysStartTrigger.jsx
new file mode 100644
index 0000000000..10068a3530
--- /dev/null
+++ b/front/src/routes/scene/edit-scene/triggers/GladysStartTrigger.jsx
@@ -0,0 +1,19 @@
+import { Component } from 'preact';
+import { connect } from 'unistore/preact';
+import { Text } from 'preact-i18n';
+
+class GladysStartTrigger extends Component {
+ render({}, {}) {
+ return (
+
+ );
+ }
+}
+
+export default connect('', {})(GladysStartTrigger);
diff --git a/server/lib/index.js b/server/lib/index.js
index dd83c1cbfe..d66017741b 100644
--- a/server/lib/index.js
+++ b/server/lib/index.js
@@ -25,6 +25,7 @@ const System = require('./system');
const Variable = require('./variable');
const services = require('../services');
const Weather = require('./weather');
+const { EVENTS } = require('../utils/constants');
/**
* @description Start a new Gladys instance.
@@ -163,6 +164,10 @@ function Gladys(params = {}) {
scheduler.init();
}
gateway.init();
+
+ event.emit(EVENTS.TRIGGERS.CHECK, {
+ type: EVENTS.SYSTEM.START,
+ });
},
};
diff --git a/server/lib/scene/scene.triggers.js b/server/lib/scene/scene.triggers.js
index ed8134ef9d..b8b5ea91e8 100644
--- a/server/lib/scene/scene.triggers.js
+++ b/server/lib/scene/scene.triggers.js
@@ -25,6 +25,7 @@ const triggersFunc = {
[EVENTS.HOUSE.NO_LONGER_EMPTY]: (event, trigger) => event.house === trigger.house,
[EVENTS.AREA.USER_ENTERED]: (event, trigger) => event.user === trigger.user && event.area === trigger.area,
[EVENTS.AREA.USER_LEFT]: (event, trigger) => event.user === trigger.user && event.area === trigger.area,
+ [EVENTS.SYSTEM.START]: () => true,
};
module.exports = {
diff --git a/server/test/lib/scene/scene.checkTrigger.test.js b/server/test/lib/scene/scene.checkTrigger.test.js
index 458586be1e..63ec03f99c 100644
--- a/server/test/lib/scene/scene.checkTrigger.test.js
+++ b/server/test/lib/scene/scene.checkTrigger.test.js
@@ -446,6 +446,39 @@ describe('scene.checkTrigger', () => {
});
});
+ it('should execute scene with system start trigger', async () => {
+ sceneManager.addScene({
+ selector: 'my-scene',
+ active: true,
+ actions: [
+ [
+ {
+ type: ACTIONS.LIGHT.TURN_OFF,
+ devices: ['light-1'],
+ },
+ ],
+ ],
+ triggers: [
+ {
+ type: EVENTS.SYSTEM.START,
+ },
+ ],
+ });
+ sceneManager.checkTrigger({
+ type: EVENTS.SYSTEM.START,
+ });
+ return new Promise((resolve, reject) => {
+ sceneManager.queue.start(() => {
+ try {
+ assert.calledOnce(device.setValue);
+ resolve();
+ } catch (e) {
+ reject(e);
+ }
+ });
+ });
+ });
+
it('should not execute scene, condition not verified', async () => {
sceneManager.addScene({
selector: 'my-scene',
diff --git a/server/utils/constants.js b/server/utils/constants.js
index 0775f33bc3..4cfef7dbb7 100644
--- a/server/utils/constants.js
+++ b/server/utils/constants.js
@@ -202,6 +202,7 @@ const EVENTS = {
CHECK_UPGRADE: 'system.check-upgrade',
TIMEZONE_CHANGED: 'system.timezone-changed',
VACUUM: 'system.vacuum',
+ START: 'system.start',
},
WEBSOCKET: {
SEND: 'websocket.send',