Hi,
I have a sensor A that contains data of heating energy used. The format is:
energy,timestamp energy,timestamp, …
The energy data is available for past 14 hours and I’m trying to insert this “consumption history data” to another sensor’s (B) history. So I have the history in these data pairs, but I would like to put them into sensor states for being able to see them as normal history data of a sensor. Uh, that was difficult to explain, hopefully you understood!
I have successfully parsed the data pairs in NodeRed using SPLIT node which basically initiates flow for each pair of data. For each pair of data I would like to fire state_changed event with the consumption values and timestamps (that are in the past). I just cannot figure out the input values for the FIRE-EVENT node. Could someone help with this? This is what I have currently:
msg.topic = "state_changed";
msg.event_type = "state_changed";
msg.payload.event = "state_changed";
msg.payload.entity_id = "sensor.lattian_energiakulutus";
msg.data.entity_id = "sensor.lattian_energiakulutus";
msg.data.old_state.entity_id = "sensor.lattian_energiakulutus";
msg.data.old_state.state = 0;
msg.data.new_state.state = 1;
msg.data.new_state.entity_id = "sensor.lattian_energiakulutus";
return msg;
And this is what comes out of it:
{"topic":"state_changed","payload":{"event":"state_changed","data":null},"data":{"entity_id":"sensor.lattian_energiakulutus","old_state":{"entity_id":"sensor.lattian_energiakulutus","state":1,"attributes":{"unit_of_measurement":"","friendly_name":"themo_energia_raw"},"last_changed":"2022-10-19T15:01:12.038924+00:00","last_updated":"2022-10-19T15:01:12.038924+00:00","context":{"id":"01GFRC6GQ68ZPN6MMT8Q9YQBDC","parent_id":null,"user_id":null},"original_state":"0.0,1666144800.0 0.0,1666148400.0 0.0,1666152000.0 0.0,1666155600.0 0.0,1666159200.0 0.0,1666162800.0 0.0,1666166400.0 0.0,1666170000.0 0.0,1666173600.0 0.0,1666177200.0 0.0,1666180800.0 0.0,1666184400.0 0.0,1666188000.0 0.0,1666191600.0","timeSinceChangedMs":3182927},"new_state":{"entity_id":"sensor.lattian_energiakulutus","state":1,"attributes":{"unit_of_measurement":"","friendly_name":"themo_energia_raw"},"last_changed":"2022-10-19T15:01:12.038924+00:00","last_updated":"2022-10-19T15:01:12.038924+00:00","context":{"id":"01GFRC6GQ68ZPN6MMT8Q9YQBDC","parent_id":null,"user_id":null},"original_state":"0.0,1666144800.0 0.0,1666148400.0 0.0,1666152000.0 0.0,1666155600.0 0.0,1666159200.0 0.0,1666162800.0 0.0,1666166400.0 0.0,1666170000.0 0.0,1666173600.0 0.0,1666177200.0 0.0,1666180800.0 0.0,1666184400.0 0.0,1666188000.0 0.0,1666191600.0","timeSinceChangedMs":3182927}},"parts":{"id":"fbcc5a3f300aa8a2","type":"string","ch":" ","index":11,"count":14,"date":"10/19/2022, 4:00:00 PM","value":0},"_msgid":"ff59cd9d9ba6e47e","event_type":"state_changed"}
There are some fields that are not probably needed, but which one? What are the parameters that are needed at minimum. The node sends the event (above), but it does not end up to sensor B history.
FIRE-EVENT node says:
Inputs:
If the incoming message has a
payload
property withevent
set it will override any config values if set. If the incoming message has apayload.data
that is an object or parsable into an object these properties will be merged with any config values set. If the node has a property value in its config forMerge Context
then theflow
andglobal
contexts will be checked for this property which should be an object that will also be merged into the data payload.payload.event string
Event to firepayload.data Object
Event data to send
I suppose my problem is payload.data. Any ideas what should be in that?